Submission #1695725
Source Code Expand
//#define __USE_MINGW_ANSI_STDIO 0 #include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<ll> VL; typedef vector<VL> VVL; typedef pair<int, int> PII; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define IN(a, b, x) (a<=x&&x<b) #define MP make_pair #define PB push_back #ifdef int const ll INF = (1LL<<60); #else const int INF = (1LL<<30); #endif const double PI = 3.14159265359; const double EPS = 1e-12; const int MOD = 1000000007; template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; int x[100010], y[100010], c[100010]; vector<PII> a[100010], b[100010]; signed main(void) { int R, C; cin >> R >> C; int n; cin >> n; REP(i, n) { cin >> y[i] >> x[i] >> c[i]; a[x[i]].PB({y[i], c[i]}); b[y[i]].PB({x[i], c[i]}); } int idx = -1; REP(i, R+1) sort(ALL(b[i])); REP(i, R+1) { if(b[i].size()>=2) { idx = i; break; } } // cout << idx << endl; if(idx != -1) { // 公差を求める int d = -1; int num1 = b[idx][0].first, c1 = b[idx][0].second, num2 = b[idx][1].first, c2 = b[idx][1].second; if(num1 < num2) { if((c2-c1)%(num2-num1)) {cout << "No" << endl; return 0;} d = (c2-c1)/(num2-num1); } else { if((c1-c2)%(num1-num2)) {cout << "No" << endl; return 0;} d = (c1-c2)/(num1-num2); } REP(i, R+1) { if(b[i].size()==0) continue; FOR(j, 1, b[i].size()) { if((b[i][j].first-b[i][j-1].first)*d != b[i][j].second-b[i][j-1].second) { cout << "No" << endl; return 0; } } if(b[i][0].second - (b[i][0].first-1)*d < 0) { cout << "No" << endl; return 0; } if(b[i][b[i].size()-1].second + (C-b[i][b[i].size()-1].first)*d < 0) { cout << "No" << endl; return 0; } } } idx = -1; REP(i, C+1) sort(ALL(a[i])); REP(i, C+1) { if(a[i].size()>=2) { idx = i; break; } } if(idx != -1) { // 公差を求める int d = -1; int num1 = a[idx][0].first, c1 = a[idx][0].second, num2 = a[idx][1].first, c2 = a[idx][1].second; if(num1 < num2) { if((c2-c1)%(num2-num1)) {cout << "No" << endl; return 0;} d = (c2-c1)/(num2-num1); } else { if((c1-c2)%(num1-num2)) {cout << "No" << endl; return 0;} d = (c1-c2)/(num1-num2); } REP(i, C+1) { if(a[i].size()==0) continue; FOR(j, 1, a[i].size()) { if((a[i][j].first-a[i][j-1].first)*d != a[i][j].second-a[i][j-1].second) { cout << "No" << endl; return 0; } } if(a[i][0].second - (a[i][0].first-1)*d < 0) { cout << "No" << endl; return 0; } if(a[i][a[i].size()-1].second + (R-a[i][a[i].size()-1].first)*d < 0) { cout << "No" << endl; return 0; } } } cout << "Yes" << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Grid and Integers |
User | ferin_tech |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 3263 Byte |
Status | WA |
Exec Time | 138 ms |
Memory | 13568 KB |
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 800 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt, 1_47.txt, 1_48.txt, 1_49.txt, 1_50.txt, 1_51.txt, 1_52.txt, 1_53.txt, 1_54.txt, 1_55.txt, 1_56.txt, 1_57.txt, 1_58.txt, 1_59.txt, 1_60.txt, 1_61.txt, 1_62.txt, 1_63.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 4 ms | 6400 KB |
0_01.txt | AC | 4 ms | 6400 KB |
0_02.txt | AC | 4 ms | 6400 KB |
0_03.txt | AC | 4 ms | 6400 KB |
0_04.txt | AC | 4 ms | 6400 KB |
1_00.txt | AC | 4 ms | 6400 KB |
1_01.txt | AC | 4 ms | 6400 KB |
1_02.txt | AC | 4 ms | 6400 KB |
1_03.txt | AC | 4 ms | 6400 KB |
1_04.txt | AC | 4 ms | 6400 KB |
1_05.txt | AC | 4 ms | 6400 KB |
1_06.txt | AC | 105 ms | 13568 KB |
1_07.txt | AC | 133 ms | 13568 KB |
1_08.txt | AC | 117 ms | 12800 KB |
1_09.txt | AC | 104 ms | 12672 KB |
1_10.txt | AC | 138 ms | 12544 KB |
1_11.txt | AC | 132 ms | 12544 KB |
1_12.txt | AC | 136 ms | 12544 KB |
1_13.txt | AC | 129 ms | 12544 KB |
1_14.txt | AC | 138 ms | 12544 KB |
1_15.txt | AC | 130 ms | 12544 KB |
1_16.txt | AC | 108 ms | 12544 KB |
1_17.txt | AC | 123 ms | 12544 KB |
1_18.txt | AC | 120 ms | 12544 KB |
1_19.txt | AC | 122 ms | 12544 KB |
1_20.txt | AC | 78 ms | 10112 KB |
1_21.txt | WA | 38 ms | 8192 KB |
1_22.txt | WA | 8 ms | 6656 KB |
1_23.txt | WA | 79 ms | 10240 KB |
1_24.txt | AC | 97 ms | 11008 KB |
1_25.txt | AC | 78 ms | 10112 KB |
1_26.txt | WA | 10 ms | 6784 KB |
1_27.txt | WA | 16 ms | 7040 KB |
1_28.txt | AC | 121 ms | 12416 KB |
1_29.txt | WA | 43 ms | 8448 KB |
1_30.txt | AC | 117 ms | 12032 KB |
1_31.txt | WA | 48 ms | 8704 KB |
1_32.txt | AC | 97 ms | 11392 KB |
1_33.txt | AC | 120 ms | 12032 KB |
1_34.txt | WA | 17 ms | 7168 KB |
1_35.txt | WA | 103 ms | 11520 KB |
1_36.txt | WA | 20 ms | 7296 KB |
1_37.txt | AC | 48 ms | 8704 KB |
1_38.txt | WA | 90 ms | 10752 KB |
1_39.txt | WA | 31 ms | 7808 KB |
1_40.txt | WA | 95 ms | 10496 KB |
1_41.txt | WA | 44 ms | 8448 KB |
1_42.txt | AC | 110 ms | 11520 KB |
1_43.txt | AC | 88 ms | 10240 KB |
1_44.txt | AC | 109 ms | 11264 KB |
1_45.txt | AC | 31 ms | 7936 KB |
1_46.txt | AC | 118 ms | 11904 KB |
1_47.txt | WA | 40 ms | 8320 KB |
1_48.txt | AC | 37 ms | 8064 KB |
1_49.txt | WA | 15 ms | 7040 KB |
1_50.txt | AC | 68 ms | 9472 KB |
1_51.txt | AC | 119 ms | 11904 KB |
1_52.txt | WA | 11 ms | 6784 KB |
1_53.txt | WA | 20 ms | 7296 KB |
1_54.txt | WA | 36 ms | 8192 KB |
1_55.txt | WA | 50 ms | 8832 KB |
1_56.txt | AC | 83 ms | 10240 KB |
1_57.txt | AC | 125 ms | 12288 KB |
1_58.txt | AC | 105 ms | 11264 KB |
1_59.txt | WA | 9 ms | 6656 KB |
1_60.txt | AC | 4 ms | 6400 KB |
1_61.txt | AC | 4 ms | 6400 KB |
1_62.txt | AC | 4 ms | 6400 KB |
1_63.txt | AC | 4 ms | 6400 KB |