Submission #1609049
Source Code Expand
#include <bits/stdc++.h> #define FOR(i,b,e) for(int i=(b); i <= (e); ++i) #define FORD(i,b,e) for(int i=(b); i >= (e); --i) #define SIZE(c) (int) (c).size() #define FORE(i,c) FOR(i,0,SIZE(c)-1) #define FORDE(i,c) FORD(i,SIZE(c)-1,0) #define pb push_back #define mp make_pair #define st first #define nd second using namespace std; typedef long long ll; typedef pair <int,int> pii; typedef pair <ll,ll> pll; typedef vector <int> VI; typedef vector <bool> VB; typedef vector <pii> VP; typedef vector <ll> VL; typedef vector <pll> VPL; typedef vector <VI> VVI; typedef vector <VL> VVL; typedef vector <VB> VVB; typedef vector <VP> VVP; const int MOD = 1000000007; const int INF = 1000000001; const ll LINF = 1000000000000000001LL; /*************************************************************************/ int main() { ios_base::sync_with_stdio(0); int r, c, n; cin >> r >> c >> n; VVP g(r + c); FOR(_,1,n) { int x, y, val; cin >> x >> y >> val; x--; y--; g[x].pb({r + y, val}); g[r + y].pb({x, val}); } VL value(r + c, -1); VVI component; queue <int> q; FOR(i,0,r+c-1) if (value[i] == -1) { component.emplace_back(); q.push(i); value[i] = 0; while (!q.empty()) { int v = q.front(); q.pop(); component.back().pb(v); for (auto e : g[v]) { int u = e.st; int newValue = e.nd - value[v]; if (value[u] != -1 && value[u] != newValue) { cout << "No"; return 0; } if (value[u] == -1) { value[u] = newValue; q.push(u); } } } } for (auto &c : component) { ll minRow = LINF; ll minCol = LINF; for (int v : c) { if (v < r) { minRow = min(minRow, value[v]); } else { minCol = min(minCol, value[v]); } } if (minRow + minCol < 0) { cout << "No"; return 0; } } cout << "Yes"; return 0; } /*************************************************************************/
Submission Info
Submission Time | |
---|---|
Task | D - Grid and Integers |
User | krismaz |
Language | C++14 (GCC 5.4.1) |
Score | 800 |
Code Size | 2522 Byte |
Status | AC |
Exec Time | 85 ms |
Memory | 19380 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 800 / 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 | 1 ms | 256 KB |
0_01.txt | AC | 1 ms | 256 KB |
0_02.txt | AC | 1 ms | 256 KB |
0_03.txt | AC | 1 ms | 256 KB |
0_04.txt | AC | 1 ms | 256 KB |
1_00.txt | AC | 20 ms | 18860 KB |
1_01.txt | AC | 20 ms | 18220 KB |
1_02.txt | AC | 20 ms | 18348 KB |
1_03.txt | AC | 20 ms | 17964 KB |
1_04.txt | AC | 20 ms | 18224 KB |
1_05.txt | AC | 4 ms | 6912 KB |
1_06.txt | AC | 67 ms | 19252 KB |
1_07.txt | AC | 63 ms | 19380 KB |
1_08.txt | AC | 59 ms | 16176 KB |
1_09.txt | AC | 57 ms | 16176 KB |
1_10.txt | AC | 62 ms | 16560 KB |
1_11.txt | AC | 53 ms | 12216 KB |
1_12.txt | AC | 59 ms | 15468 KB |
1_13.txt | AC | 47 ms | 10236 KB |
1_14.txt | AC | 85 ms | 15468 KB |
1_15.txt | AC | 59 ms | 16496 KB |
1_16.txt | AC | 56 ms | 16496 KB |
1_17.txt | AC | 57 ms | 15468 KB |
1_18.txt | AC | 57 ms | 15468 KB |
1_19.txt | AC | 58 ms | 16624 KB |
1_20.txt | AC | 31 ms | 4732 KB |
1_21.txt | AC | 24 ms | 10932 KB |
1_22.txt | AC | 9 ms | 6068 KB |
1_23.txt | AC | 43 ms | 14132 KB |
1_24.txt | AC | 37 ms | 5484 KB |
1_25.txt | AC | 32 ms | 6200 KB |
1_26.txt | AC | 6 ms | 1980 KB |
1_27.txt | AC | 17 ms | 9648 KB |
1_28.txt | AC | 52 ms | 9460 KB |
1_29.txt | AC | 26 ms | 10292 KB |
1_30.txt | AC | 50 ms | 10896 KB |
1_31.txt | AC | 34 ms | 19120 KB |
1_32.txt | AC | 36 ms | 4096 KB |
1_33.txt | AC | 52 ms | 10896 KB |
1_34.txt | AC | 15 ms | 10036 KB |
1_35.txt | AC | 36 ms | 4224 KB |
1_36.txt | AC | 17 ms | 10036 KB |
1_37.txt | AC | 19 ms | 3072 KB |
1_38.txt | AC | 46 ms | 13492 KB |
1_39.txt | AC | 22 ms | 11440 KB |
1_40.txt | AC | 45 ms | 13108 KB |
1_41.txt | AC | 36 ms | 18992 KB |
1_42.txt | AC | 39 ms | 4736 KB |
1_43.txt | AC | 43 ms | 12724 KB |
1_44.txt | AC | 41 ms | 9336 KB |
1_45.txt | AC | 11 ms | 3456 KB |
1_46.txt | AC | 51 ms | 10704 KB |
1_47.txt | AC | 20 ms | 7476 KB |
1_48.txt | AC | 17 ms | 4412 KB |
1_49.txt | AC | 13 ms | 8884 KB |
1_50.txt | AC | 31 ms | 7744 KB |
1_51.txt | AC | 42 ms | 6016 KB |
1_52.txt | AC | 21 ms | 16688 KB |
1_53.txt | AC | 20 ms | 11824 KB |
1_54.txt | AC | 23 ms | 8116 KB |
1_55.txt | AC | 22 ms | 4540 KB |
1_56.txt | AC | 31 ms | 6400 KB |
1_57.txt | AC | 45 ms | 6472 KB |
1_58.txt | AC | 43 ms | 9652 KB |
1_59.txt | AC | 14 ms | 9904 KB |
1_60.txt | AC | 1 ms | 256 KB |
1_61.txt | AC | 1 ms | 256 KB |
1_62.txt | AC | 1 ms | 256 KB |
1_63.txt | AC | 1 ms | 256 KB |