QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#500938 | #1819. Cleaning Robot | askeww | WA | 1324ms | 32488kb | C++17 | 4.0kb | 2024-08-02 04:20:22 | 2024-08-02 04:20:22 |
Judging History
answer
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct node {
int x, y, size;
};
int n, m, k, x, y, size_l, size_r, counter;
vector<pair<int, int>> obstructions;
vector<vector<bool>> obstructed_map;
queue<node> q;
bool check(int size) {
vector<vector<bool>> obstructed_prefix = vector<vector<bool>>(n - size + 1, vector<bool>(m - size + 1, false));
for (int i = 0; i < k; i++) {
int x_1 = max(0, obstructions[i].first - size + 1);
int y_1 = max(0, obstructions[i].second - size + 1);
int x_2 = obstructions[i].first + 1;
int y_2 = obstructions[i].second + 1;
obstructed_prefix[x_1][y_1] = !obstructed_prefix[x_1][y_1];
if (x_2 < obstructed_prefix.size()) obstructed_prefix[x_2][y_1] = !obstructed_prefix[x_2][y_1];
if (y_2 < obstructed_prefix[0].size()) obstructed_prefix[x_1][y_2] = !obstructed_prefix[x_1][y_2];
if (x_2 < obstructed_prefix.size() && y_2 < obstructed_prefix[0].size()) obstructed_prefix[x_2][y_2] = !obstructed_prefix[x_2][y_2];
}
for (int i = 0; i + size <= n; i++) {
bool total = false;
for (int j = 0; j + size <= m; j++) {
total = total ^ obstructed_prefix[i][j];
obstructed_prefix[i][j] = (i > 0) ? obstructed_prefix[i - 1][j] : false;
obstructed_prefix[i][j] = obstructed_prefix[i][j] ^ total;
}
}
vector<vector<bool>> visited = vector<vector<bool>>(n - size + 1, vector<bool>(m - size + 1, false));
for (int i = 0; i < visited.size(); i++) {
for (int j = 0; j < visited[0].size(); j++) {
if (!obstructed_prefix[i][j]) {
q = queue<node>();
q.push({i, j, size});
while (!q.empty()) {
node cur = q.front();
q.pop();
if (cur.x < 0 || cur.y < 0 || cur.x >= visited.size() || cur.y >= visited[0].size()) continue;
if (obstructed_prefix[cur.x][cur.y] || visited[cur.x][cur.y]) continue;
visited[cur.x][cur.y] = true;
q.push({cur.x - 1, cur.y, size});
q.push({cur.x + 1, cur.y, size});
q.push({cur.x, cur.y - 1, size});
q.push({cur.x, cur.y + 1, size});
}
vector<vector<int>> visited_prefixes = vector<vector<int>>(n, vector<int>(m, 0));
for (int a = 0; a < visited.size(); a++) {
for (int b = 0; b < visited[0].size(); b++) {
if (visited[a][b]) {
int x_1 = a;
int y_1 = b;
int x_2 = a + size;
int y_2 = b + size;
visited_prefixes[x_1][y_1] = visited_prefixes[x_1][y_1] + 1;
if (x_2 < n) visited_prefixes[x_2][y_1] = visited_prefixes[x_2][y_1] - 1;
if (y_2 < m) visited_prefixes[x_1][y_2] = visited_prefixes[x_1][y_2] - 1;
if (x_2 < n && y_2 < m) visited_prefixes[x_2][y_2] = visited_prefixes[x_2][y_2] + 1;
}
}
}
for (int a = 0; a < n; a++) {
int total = 0;
for (int b = 0; b < m; b++) {
total += visited_prefixes[a][b];
visited_prefixes[a][b] = (a > 0) ? visited_prefixes[a - 1][b] : 0;
visited_prefixes[a][b] += total;
if (!obstructed_map[a][b] && visited_prefixes[a][b] == 0) {
return false;
}
}
}
return true;
}
}
}
return true;
}
int main() {
cin >> n >> m >> k;
obstructions = vector<pair<int, int>>(k);
obstructed_map = vector<vector<bool>>(n, vector<bool>(m, 0));
for (int i = 0; i < k; i++) {
cin >> obstructions[i].first >> obstructions[i].second;
obstructions[i].first--; obstructions[i].second--;
obstructed_map[obstructions[i].first][obstructions[i].second] = true;
}
size_l = 1;
size_r = min(n, m);
while (size_l < size_r) {
int size_m = (size_l + size_r + 1) / 2;
if (check(size_m)) {
size_l = size_m;
} else {
size_r = size_m - 1;
}
}
cout << size_l << endl;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
input:
10 7 1 8 3
output:
2
result:
ok answer is '2'
Test #2:
score: 0
Accepted
time: 783ms
memory: 25204kb
input:
2236 2236 2214 28 1255 389 2175 730 592 1360 977 1225 752 1403 1798 1518 1381 147 745 659 249 951 1475 1826 1951 691 1033 81 1458 1487 1946 2106 1395 1995 629 470 891 1902 822 2210 2001 441 2130 1198 1539 2027 1101 215 1149 205 420 379 2104 308 1225 859 109 1417 2078 1764 376 1772 5 335 1113 917 118...
output:
1
result:
ok answer is '1'
Test #3:
score: 0
Accepted
time: 925ms
memory: 24996kb
input:
2236 2236 2143 228 686 129 801 1105 382 2196 1919 2082 777 1672 268 174 916 234 491 1235 274 1645 1849 1114 1173 1351 1677 1294 1365 1059 197 611 1715 1769 1395 885 1902 1190 1304 1039 779 610 124 881 662 22 1664 239 1283 2218 2031 169 1417 291 143 228 1837 1518 2013 747 359 1997 1030 73 153 614 488...
output:
3
result:
ok answer is '3'
Test #4:
score: 0
Accepted
time: 403ms
memory: 25644kb
input:
2236 2236 63774 369 1861 1156 2150 1895 160 546 1944 1688 645 49 1888 430 973 1602 30 1988 971 1120 1307 322 1524 1559 1070 558 1147 973 1965 572 923 370 646 1436 1982 132 681 1410 308 1812 982 2191 2112 1311 396 1067 1330 659 477 873 881 1766 508 2091 1875 895 716 2058 1237 1374 1005 2183 1514 227 ...
output:
8
result:
ok answer is '8'
Test #5:
score: 0
Accepted
time: 459ms
memory: 25376kb
input:
2236 2236 27245 1371 170 575 488 1594 575 1537 77 491 1580 1761 764 783 1265 242 923 893 71 1455 671 114 1289 1901 1481 1962 1160 861 2198 1055 89 2019 1481 1012 1415 1023 92 421 2018 1788 2006 1559 263 1387 1496 1556 479 166 1085 1368 2156 2076 2156 1028 617 919 146 698 1544 1730 2111 871 1478 768 ...
output:
16
result:
ok answer is '16'
Test #6:
score: 0
Accepted
time: 404ms
memory: 25184kb
input:
2000 2500 30907 892 176 1238 2180 1711 176 1953 1556 793 44 336 1844 850 536 71 104 730 1052 892 1112 332 608 483 2144 45 572 240 104 201 416 1251 2024 1428 2000 402 1412 1240 1940 1689 1412 399 680 1349 1964 1290 464 1117 944 158 584 608 92 1947 1964 1042 1676 1865 1196 196 2264 1520 1724 1411 1544...
output:
11
result:
ok answer is '11'
Test #7:
score: 0
Accepted
time: 349ms
memory: 25600kb
input:
2500 2000 33483 2270 1836 1874 828 866 108 1066 220 1616 780 396 140 85 1012 2107 1492 630 1148 710 1452 688 1804 834 1196 524 1404 400 1228 1031 132 1967 1428 1480 1804 996 44 134 588 1361 900 541 1492 186 1196 835 532 1339 676 628 1468 615 308 740 540 2139 1556 1299 1892 702 1868 670 652 1201 1444...
output:
12
result:
ok answer is '12'
Test #8:
score: 0
Accepted
time: 895ms
memory: 24892kb
input:
2236 2236 2111 809 773 1351 157 1378 427 461 1897 584 2078 285 1146 283 717 421 933 1449 726 559 799 350 1344 1018 1081 106 1517 2212 870 842 1225 1717 599 338 104 92 2027 1198 915 220 568 2079 31 1611 1532 100 251 675 1098 745 1368 1879 669 941 1303 1370 1445 344 1203 473 494 539 723 1385 1813 1360...
output:
4
result:
ok answer is '4'
Test #9:
score: 0
Accepted
time: 878ms
memory: 25136kb
input:
2236 2236 2241 490 710 1582 1095 868 1869 970 1216 224 445 1901 2198 1592 732 706 696 456 2051 1107 2064 717 1109 1205 1860 510 1472 832 1607 1005 1665 644 794 858 494 1353 408 1661 306 171 1381 1586 969 174 897 896 232 120 1538 1351 1526 654 2039 1884 896 1995 1130 1492 1309 279 1674 2028 1526 1271...
output:
5
result:
ok answer is '5'
Test #10:
score: -100
Wrong Answer
time: 1324ms
memory: 32488kb
input:
2236 2236 999999 577 1462 1623 1266 1158 1238 914 1218 53 674 1599 138 395 298 1308 30 387 130 1077 1154 448 654 485 166 817 2090 769 170 549 1070 432 1390 537 686 1298 1630 989 762 133 1342 184 786 1631 1226 612 610 987 1538 1107 1394 345 678 413 2174 768 250 208 1014 393 302 70 966 845 974 1001 11...
output:
360
result:
wrong answer expected '3', found '360'