Submission #897529
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
const int maxValue = 1000000000;
void noAnswer() {
cout << "No" << endl;
exit(0);
}
int r, c;
map<pair<int, int>, int> field;
typedef vector<int> vi;
vi rowLow;
vi rowHigh;
vi colLow;
vi colHigh;
void setRowLow(int rn, int val) {
rowLow[rn] = max(rowLow[rn], val);
}
void setRowHigh(int rn, int val) {
rowHigh[rn] = min(rowHigh[rn], val);
}
void setColLow(int cn, int val) {
colLow[cn] = max(colLow[cn], val);
}
void setColHigh(int cn, int val) {
colHigh[cn] = min(colHigh[cn], val);
}
void setRow(int rn, int val) {
if (val < rowLow[rn])
noAnswer();
if (val > rowHigh[rn])
noAnswer();
setRowLow(rn, val);
setRowHigh(rn, val);
}
void setCol(int cn, int val) {
if (val < colLow[cn])
noAnswer();
if (val > colHigh[cn])
noAnswer();
setColLow(cn, val);
setColHigh(cn, val);
}
void check(int x, int y, int v) {
if (x > 0) {
auto it = field.find(make_pair(x-1, y));
if (it != field.end()) {
setRow(x-1, it->second - v);
} else {
setRowLow(x-1, -v);
}
}
if (x + 1 < r) {
auto it = field.find(make_pair(x+1, y));
if (it != field.end()) {
setRow(x, v - it->second);
} else {
setRowHigh(x, v);
}
}
if (y > 0) {
auto it = field.find(make_pair(x, y - 1));
if (it != field.end()) {
setCol(y-1, it->second - v);
} else {
setColLow(y-1, -v);
}
}
if (y + 1 < c) {
auto it = field.find(make_pair(x, y + 1));
if (it != field.end()) {
setCol(y, v - it->second);
} else {
setColHigh(y, v);
}
}
}
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
scanf("%d %d", &r, &c);
rowLow.assign(r, -maxValue);
rowHigh.assign(r, maxValue);
colLow.assign(c, -maxValue);
colHigh.assign(c, maxValue);
int n;
scanf("%d", &n);
vector<pair<int, int>> inp;
for (int i = 0; i < n; ++i) {
int a, b, v;
scanf("%d %d %d", &a, &b, &v);
--a, --b;
inp.push_back(make_pair(a, b));
field[make_pair(a, b)] = v;
check(a, b, v);
}
//for (int i = 0; i )
bool ok = true;
for (int i = 0; i < r; ++i) {
if (rowLow[i] > rowHigh[i])
ok = false;
}
for (int i = 0; i < c; ++i) {
if (colLow[i] > colHigh[i])
ok = false;
}
cout << (ok ? "Yes" : "No") << endl;
return 0;
}
Submission Info
| Submission Time |
|
| Task |
D - Grid and Integers |
| User |
kipnell |
| Language |
C++14 (GCC 5.4.1) |
| Score |
0 |
| Code Size |
2773 Byte |
| Status |
WA |
| Exec Time |
130 ms |
| Memory |
8820 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:101:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &r, &c);
^
./Main.cpp:109:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:114:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &a, &b, &v);
^
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 |
256 KiB |
| 0_01.txt |
AC |
3 ms |
384 KiB |
| 0_02.txt |
AC |
3 ms |
256 KiB |
| 0_03.txt |
AC |
3 ms |
256 KiB |
| 0_04.txt |
AC |
3 ms |
256 KiB |
| 1_00.txt |
AC |
5 ms |
1792 KiB |
| 1_01.txt |
AC |
5 ms |
1920 KiB |
| 1_02.txt |
AC |
5 ms |
1792 KiB |
| 1_03.txt |
WA |
5 ms |
1792 KiB |
| 1_04.txt |
AC |
4 ms |
1792 KiB |
| 1_05.txt |
WA |
5 ms |
1792 KiB |
| 1_06.txt |
AC |
112 ms |
8820 KiB |
| 1_07.txt |
AC |
122 ms |
8820 KiB |
| 1_08.txt |
AC |
115 ms |
8820 KiB |
| 1_09.txt |
WA |
118 ms |
8820 KiB |
| 1_10.txt |
AC |
122 ms |
8820 KiB |
| 1_11.txt |
WA |
122 ms |
8820 KiB |
| 1_12.txt |
AC |
122 ms |
8820 KiB |
| 1_13.txt |
WA |
121 ms |
8820 KiB |
| 1_14.txt |
AC |
121 ms |
8820 KiB |
| 1_15.txt |
WA |
118 ms |
8820 KiB |
| 1_16.txt |
AC |
114 ms |
8820 KiB |
| 1_17.txt |
AC |
88 ms |
7028 KiB |
| 1_18.txt |
AC |
36 ms |
4092 KiB |
| 1_19.txt |
AC |
119 ms |
8820 KiB |
| 1_20.txt |
WA |
76 ms |
5112 KiB |
| 1_21.txt |
AC |
31 ms |
2940 KiB |
| 1_22.txt |
AC |
6 ms |
1024 KiB |
| 1_23.txt |
AC |
73 ms |
5752 KiB |
| 1_24.txt |
WA |
100 ms |
6260 KiB |
| 1_25.txt |
WA |
73 ms |
5112 KiB |
| 1_26.txt |
AC |
8 ms |
768 KiB |
| 1_27.txt |
AC |
13 ms |
1792 KiB |
| 1_28.txt |
WA |
119 ms |
8180 KiB |
| 1_29.txt |
AC |
36 ms |
3324 KiB |
| 1_30.txt |
WA |
130 ms |
7796 KiB |
| 1_31.txt |
AC |
47 ms |
4092 KiB |
| 1_32.txt |
WA |
102 ms |
6388 KiB |
| 1_33.txt |
WA |
118 ms |
7796 KiB |
| 1_34.txt |
AC |
14 ms |
1664 KiB |
| 1_35.txt |
AC |
116 ms |
7412 KiB |
| 1_36.txt |
AC |
16 ms |
1920 KiB |
| 1_37.txt |
WA |
46 ms |
3320 KiB |
| 1_38.txt |
AC |
81 ms |
6648 KiB |
| 1_39.txt |
AC |
24 ms |
2684 KiB |
| 1_40.txt |
AC |
79 ms |
6520 KiB |
| 1_41.txt |
AC |
39 ms |
3964 KiB |
| 1_42.txt |
WA |
104 ms |
6644 KiB |
| 1_43.txt |
WA |
73 ms |
5752 KiB |
| 1_44.txt |
WA |
97 ms |
7028 KiB |
| 1_45.txt |
WA |
33 ms |
2684 KiB |
| 1_46.txt |
WA |
108 ms |
7796 KiB |
| 1_47.txt |
AC |
40 ms |
3196 KiB |
| 1_48.txt |
WA |
32 ms |
2684 KiB |
| 1_49.txt |
AC |
12 ms |
1536 KiB |
| 1_50.txt |
WA |
63 ms |
4600 KiB |
| 1_51.txt |
WA |
111 ms |
7284 KiB |
| 1_52.txt |
AC |
9 ms |
1792 KiB |
| 1_53.txt |
AC |
17 ms |
2304 KiB |
| 1_54.txt |
AC |
32 ms |
2940 KiB |
| 1_55.txt |
AC |
46 ms |
3576 KiB |
| 1_56.txt |
WA |
74 ms |
5624 KiB |
| 1_57.txt |
WA |
128 ms |
7796 KiB |
| 1_58.txt |
WA |
97 ms |
6772 KiB |
| 1_59.txt |
AC |
7 ms |
1408 KiB |
| 1_60.txt |
AC |
3 ms |
256 KiB |
| 1_61.txt |
AC |
3 ms |
256 KiB |
| 1_62.txt |
AC |
3 ms |
256 KiB |
| 1_63.txt |
AC |
3 ms |
256 KiB |