Submission #895509
Source Code Expand
#include <iostream> #include <vector> #include <algorithm> #include <map> using namespace std; vector<vector<pair<int,int>>> rows; vector<vector<pair<int,int>>> cols; map<pair<int,int>, int> rdiff; map<pair<int,int>, int> cdiff; int main() { int R,C; int N; cin >> R >> C >> N; rows = vector<vector<pair<int,int> >>(R); cols = vector<vector<pair<int,int> >>(C); for(int i = 0; i < N; i++) { int r, c, a; cin >> r >> c >> a; r--;c--; rows[r].emplace_back(c, a); cols[c].emplace_back(r, a); } // check rows bool ok = true; for(int sw = 0; sw < 2; sw++) { vector<int> minc(cols.size()); vector<pair<pair<int,int>,int>> diffs; rdiff.clear(); for(int i = 0; i < cols.size(); i++) { if(cols[i].size() > 0) { minc[i] = cols[i][0].second; for(size_t j = 1; j < cols[i].size(); j++) { minc[i] = min(minc[i], cols[i][j].second); } } } for(int i = 0; i < rows.size(); i++) { sort(rows[i].begin(), rows[i].end()); for(int j = 0; j < (int)rows[i].size() - 1; j++) { int diff = rows[i][j+1].second - rows[i][j].second; auto p = make_pair(rows[i][j].first, rows[i][j+1].first); diffs.push_back(make_pair(make_pair(rows[i][j+1].first, rows[i][j].first), diff)); if(rdiff.count(p)) { if(rdiff[p] != diff) ok = false; }else { rdiff[p] = diff; } if(diff < -minc[rows[i][j].first]) ok = false; if(-diff < -minc[rows[i][j + 1].first]) ok = false; } } // 推移率の確認 sort(diffs.begin(), diffs.end()); vector<long> p(cols.size(), 0); vector<bool> u(cols.size(), false); for(auto t: diffs) { int start = t.first.second; int end = t.first.first; int diff = t.second; if(!u[start] && !u[end]) { u[start] = u[end] = true; p[start] = 0; p[end] = diff; }else if(u[start] && u[end]) { if(p[end] - p[start] != diff) ok = false; }else if(u[start] && !u[end]) { u[end] = true; p[end] = p[start] + diff; }else { p[start] = p[end] - diff; u[start] = true; } } swap(rows, cols); } if(ok) cout << "Yes" << endl; else cout << "No" << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Grid and Integers |
User | staka |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2357 Byte |
Status | WA |
Exec Time | 207 ms |
Memory | 13524 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 | 3 ms | 384 KB |
0_01.txt | AC | 3 ms | 256 KB |
0_02.txt | AC | 3 ms | 256 KB |
0_03.txt | AC | 3 ms | 256 KB |
0_04.txt | AC | 3 ms | 256 KB |
1_00.txt | AC | 11 ms | 6144 KB |
1_01.txt | AC | 11 ms | 6144 KB |
1_02.txt | AC | 11 ms | 6144 KB |
1_03.txt | AC | 11 ms | 6144 KB |
1_04.txt | AC | 11 ms | 6144 KB |
1_05.txt | AC | 11 ms | 6144 KB |
1_06.txt | AC | 123 ms | 12416 KB |
1_07.txt | AC | 156 ms | 12520 KB |
1_08.txt | AC | 162 ms | 13336 KB |
1_09.txt | AC | 156 ms | 13336 KB |
1_10.txt | AC | 184 ms | 12116 KB |
1_11.txt | AC | 180 ms | 11988 KB |
1_12.txt | AC | 187 ms | 13268 KB |
1_13.txt | AC | 196 ms | 13524 KB |
1_14.txt | AC | 195 ms | 13268 KB |
1_15.txt | WA | 201 ms | 13524 KB |
1_16.txt | AC | 176 ms | 13268 KB |
1_17.txt | AC | 181 ms | 13268 KB |
1_18.txt | AC | 173 ms | 13268 KB |
1_19.txt | AC | 175 ms | 13268 KB |
1_20.txt | AC | 120 ms | 7608 KB |
1_21.txt | WA | 46 ms | 4992 KB |
1_22.txt | AC | 10 ms | 2816 KB |
1_23.txt | WA | 101 ms | 9148 KB |
1_24.txt | AC | 153 ms | 9016 KB |
1_25.txt | AC | 108 ms | 7180 KB |
1_26.txt | WA | 11 ms | 1280 KB |
1_27.txt | WA | 21 ms | 4608 KB |
1_28.txt | AC | 187 ms | 12200 KB |
1_29.txt | WA | 53 ms | 5676 KB |
1_30.txt | AC | 166 ms | 12088 KB |
1_31.txt | WA | 60 ms | 7808 KB |
1_32.txt | AC | 176 ms | 9144 KB |
1_33.txt | AC | 165 ms | 11960 KB |
1_34.txt | WA | 21 ms | 3712 KB |
1_35.txt | WA | 168 ms | 11036 KB |
1_36.txt | WA | 25 ms | 4344 KB |
1_37.txt | AC | 74 ms | 4660 KB |
1_38.txt | WA | 116 ms | 10044 KB |
1_39.txt | WA | 35 ms | 5516 KB |
1_40.txt | WA | 118 ms | 10140 KB |
1_41.txt | WA | 53 ms | 7804 KB |
1_42.txt | AC | 177 ms | 9912 KB |
1_43.txt | AC | 105 ms | 9184 KB |
1_44.txt | AC | 160 ms | 12536 KB |
1_45.txt | AC | 47 ms | 5564 KB |
1_46.txt | AC | 169 ms | 11064 KB |
1_47.txt | WA | 59 ms | 6716 KB |
1_48.txt | AC | 48 ms | 3912 KB |
1_49.txt | WA | 17 ms | 3072 KB |
1_50.txt | AC | 94 ms | 7416 KB |
1_51.txt | AC | 178 ms | 10164 KB |
1_52.txt | AC | 16 ms | 5248 KB |
1_53.txt | WA | 26 ms | 5376 KB |
1_54.txt | WA | 50 ms | 5588 KB |
1_55.txt | WA | 78 ms | 6356 KB |
1_56.txt | AC | 116 ms | 9292 KB |
1_57.txt | AC | 207 ms | 11192 KB |
1_58.txt | AC | 151 ms | 10528 KB |
1_59.txt | AC | 13 ms | 3840 KB |
1_60.txt | AC | 3 ms | 256 KB |
1_61.txt | AC | 3 ms | 256 KB |
1_62.txt | AC | 3 ms | 256 KB |
1_63.txt | AC | 3 ms | 256 KB |