Submission #1338556
Source Code Expand
#include<iostream> #include<algorithm> #include<vector> #include<queue> using namespace std; long long H, W, N, a, b, c, dist[100009]; vector<pair<int, int>>X[100009], Y[100009]; vector<pair<int, int>>x[100009], y[100009]; int main() { cin >> H >> W >> N; for (int i = 0; i < N; i++) { cin >> a >> b >> c; X[a].push_back(make_pair(b, c)); Y[b].push_back(make_pair(a, c)); } for (int i = 1; i <= H; i++) { sort(X[i].begin(), X[i].end()); for (int j = 0; j < (int)X[i].size() - 1; j++) { x[X[i][j].first].push_back(make_pair(X[i][j + 1].first, X[i][j + 1].second - X[i][j].second)); x[X[i][j + 1].first].push_back(make_pair(X[i][j].first, X[i][j].second - X[i][j + 1].second)); } } for (int i = 1; i <= W; i++) { sort(Y[i].begin(), Y[i].end()); for (int j = 0; j < (int)Y[i].size() - 1; j++) { y[Y[i][j].first].push_back(make_pair(Y[i][j + 1].first, Y[i][j + 1].second - Y[i][j].second)); y[Y[i][j + 1].first].push_back(make_pair(Y[i][j].first, Y[i][j].second - Y[i][j + 1].second)); } } queue<int>Q; for (int h = 1; h <= H; h++)dist[h] = (1LL << 60); for (int h = 1; h <= H; h++) { if (dist[h] != (1LL << 60))continue; dist[h] = 0; Q.push(h); while (!Q.empty()) { int a1 = Q.front(); Q.pop(); for (int i = 0; i < x[a1].size(); i++) { if (dist[x[a1][i].first] == (1LL << 60)) { dist[x[a1][i].first] = dist[a1] + x[a1][i].second; } else if (dist[x[a1][i].first] != dist[a1] + x[a1][i].second) { cout << "No" << endl; return 0; } } } } for (int h = 1; h <= W; h++)dist[h] = (1LL << 60); for (int h = 1; h <= W; h++) { if (dist[h] != (1LL << 60))continue; dist[h] = 0; Q.push(h); while (!Q.empty()) { int a1 = Q.front(); Q.pop(); for (int i = 0; i < y[a1].size(); i++) { if (dist[y[a1][i].first] == (1LL << 60)) { dist[y[a1][i].first] = dist[a1] + y[a1][i].second; } else if (dist[y[a1][i].first] != dist[a1] + y[a1][i].second) { cout << "No" << endl; return 0; } } } } cout << "Yes" << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Grid and Integers |
User | E869120 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2085 Byte |
Status | WA |
Exec Time | 139 ms |
Memory | 18688 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 | 9600 KB |
0_01.txt | AC | 4 ms | 9600 KB |
0_02.txt | WA | 4 ms | 9600 KB |
0_03.txt | AC | 4 ms | 9600 KB |
0_04.txt | AC | 4 ms | 9600 KB |
1_00.txt | AC | 6 ms | 10368 KB |
1_01.txt | AC | 6 ms | 10368 KB |
1_02.txt | AC | 6 ms | 10368 KB |
1_03.txt | WA | 6 ms | 10368 KB |
1_04.txt | AC | 6 ms | 10368 KB |
1_05.txt | AC | 5 ms | 10368 KB |
1_06.txt | AC | 94 ms | 16640 KB |
1_07.txt | AC | 124 ms | 16640 KB |
1_08.txt | AC | 109 ms | 18688 KB |
1_09.txt | WA | 121 ms | 18688 KB |
1_10.txt | AC | 139 ms | 16640 KB |
1_11.txt | AC | 135 ms | 16640 KB |
1_12.txt | AC | 139 ms | 16640 KB |
1_13.txt | AC | 137 ms | 16640 KB |
1_14.txt | AC | 138 ms | 16640 KB |
1_15.txt | WA | 139 ms | 16640 KB |
1_16.txt | AC | 113 ms | 16640 KB |
1_17.txt | AC | 122 ms | 16640 KB |
1_18.txt | AC | 122 ms | 16640 KB |
1_19.txt | AC | 126 ms | 16640 KB |
1_20.txt | AC | 85 ms | 14208 KB |
1_21.txt | WA | 38 ms | 12032 KB |
1_22.txt | WA | 9 ms | 10368 KB |
1_23.txt | WA | 83 ms | 14720 KB |
1_24.txt | AC | 102 ms | 15232 KB |
1_25.txt | AC | 80 ms | 14208 KB |
1_26.txt | WA | 11 ms | 10112 KB |
1_27.txt | WA | 18 ms | 10496 KB |
1_28.txt | AC | 131 ms | 17280 KB |
1_29.txt | WA | 44 ms | 12416 KB |
1_30.txt | AC | 121 ms | 16640 KB |
1_31.txt | WA | 48 ms | 12800 KB |
1_32.txt | AC | 106 ms | 15616 KB |
1_33.txt | AC | 123 ms | 16640 KB |
1_34.txt | WA | 19 ms | 10624 KB |
1_35.txt | WA | 113 ms | 16256 KB |
1_36.txt | WA | 21 ms | 11264 KB |
1_37.txt | AC | 53 ms | 12544 KB |
1_38.txt | WA | 90 ms | 15360 KB |
1_39.txt | WA | 29 ms | 11648 KB |
1_40.txt | WA | 90 ms | 15488 KB |
1_41.txt | WA | 45 ms | 12672 KB |
1_42.txt | AC | 109 ms | 15872 KB |
1_43.txt | AC | 85 ms | 14976 KB |
1_44.txt | AC | 110 ms | 16256 KB |
1_45.txt | AC | 34 ms | 11520 KB |
1_46.txt | AC | 117 ms | 16512 KB |
1_47.txt | WA | 45 ms | 12032 KB |
1_48.txt | AC | 40 ms | 11904 KB |
1_49.txt | WA | 15 ms | 10496 KB |
1_50.txt | AC | 71 ms | 13952 KB |
1_51.txt | AC | 120 ms | 16384 KB |
1_52.txt | WA | 12 ms | 10496 KB |
1_53.txt | WA | 21 ms | 10880 KB |
1_54.txt | WA | 41 ms | 12288 KB |
1_55.txt | WA | 53 ms | 12928 KB |
1_56.txt | AC | 87 ms | 14976 KB |
1_57.txt | AC | 130 ms | 16768 KB |
1_58.txt | AC | 112 ms | 16000 KB |
1_59.txt | WA | 10 ms | 10240 KB |
1_60.txt | WA | 5 ms | 9600 KB |
1_61.txt | WA | 4 ms | 9600 KB |
1_62.txt | AC | 4 ms | 9600 KB |
1_63.txt | AC | 4 ms | 9600 KB |