QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#483675#1819. Cleaning Robotpatboi008WA 251ms82572kbC++173.6kb2024-07-19 01:35:212024-07-19 01:35:21

Judging History

你现在查看的是最新测评结果

  • [2024-07-19 01:35:21]
  • 评测
  • 测评结果:WA
  • 用时:251ms
  • 内存:82572kb
  • [2024-07-19 01:35:21]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

void applySetter(vector<vector<int>>& cleaned, int x1, int y1, int x2, int y2) {
    cleaned[x1][y1]++;
    cleaned[x1][y2 + 1]--;
    cleaned[x2 + 1][y1]--;
    cleaned[x2 + 1][y2 + 1]++;
}

bool checkCoverage(vector<vector<int>>& obs, vector<vector<int>>& cleaned, int n, int m) {
    vector<vector<int>> result(n + 1, vector<int>(m + 1, 0));
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            result[i][j] = cleaned[i][j] + result[i - 1][j] + result[i][j - 1] - result[i - 1][j - 1];
            if (obs[i][j] == 0 && result[i][j] <= 0) {
                return false;
            }
        }
    }
    return true;
}

bool canCoverAll(vector<vector<int>>& obs, vector<vector<int>>& obsPrefix, int size, int n, int m) {
    vector<vector<int>> cleaned(n + 2, vector<int>(m + 2, 0));
    for (int i = 1; i <= n - size + 1; i++) {
        for (int j = 1; j <= m - size + 1; j++) {
            int x1 = i, y1 = j;
            int x2 = i + size - 1, y2 = j + size - 1;
            int obsCount = obsPrefix[x2][y2] - obsPrefix[x1 - 1][y2] - obsPrefix[x2][y1 - 1] + obsPrefix[x1 - 1][y1 - 1];
            if (obsCount == 0) {
                applySetter(cleaned, x1, y1, x2, y2);
            }
        }
    }
    return checkCoverage(obs, cleaned, n, m);
}
/*
void visAll(vector<vector<bool>>& vis, vector<vector<int>>& obs, int i, int j, int& n, int& m){
  if(i <= 0 || j <= 0 || i > n || j > m || obs[i][j] == 1 || vis[i][j]){
    return;
  }
  vis[i][j] = true;
  visAll(vis, obs, i+1, j, n, m);
  visAll(vis, obs, i, j+1, n, m);
  visAll(vis, obs, i-1, j, n, m);
  visAll(vis, obs, i, j-1, n, m);
  return;
}
*/
int main() {
    int n, m, k;
    cin >> n >> m >> k;
  
    vector<vector<int>> obstructed(n + 2, vector<int>(m + 2, 0));
    for (int i = 0; i < k; i++) {
        int a, b;
        cin >> a >> b;
        obstructed[a][b] = 1;
    }
  if(k == n*m){
    cout << "-1" << endl;
    return 0;
  }
  vector<vector<bool>> visited(n + 2, vector<bool>(m + 2, false));
  queue<pair<int, int>> q;
  
  bool breaker = false;
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      if(obstructed[i][j] == 0){
        q.push(make_pair(i, j));
        breaker = true;
        break;
      }
    }
    if(breaker){
      break;
    }
  }
  
  while(!q.empty()){
    int x = q.front().first;
    int y = q.front().second;
    q.pop();
    if(x <= 0 || y <= 0 || x > n || y > m || visited[x][y] || obstructed[x][y] == 1){
      continue;
    }
    visited[x][y] = true;
    q.push(make_pair(x+1, y));
    q.push(make_pair(x, y+1));
    q.push(make_pair(x-1, y));
    q.push(make_pair(x, y-1));
  }
  
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= m; j++){
      if(!visited[i][j] && obstructed[i][j] == 0){
        cout << "-1 " << endl;
        return 0;
      }
    }
  }
    vector<vector<int>> obsPrefix(n + 1, vector<int>(m + 1, 0));
  
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            obsPrefix[i][j] = obstructed[i][j] + obsPrefix[i - 1][j] + obsPrefix[i][j - 1] - obsPrefix[i - 1][j - 1];
        }
    }

    int left = 1, right = min(n, m), ans = 0;
    while (left <= right) {
        int mid = left + (right-left)/2;
        if (canCoverAll(obstructed, obsPrefix, mid, n, m)) {
            ans = mid;
            left = mid + 1;
        } else {
            right = mid - 1;
        }
    }
  if(ans == 0){
    cout << "-1" << endl;
    return 0;
  }
  cout << ans << endl;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3580kb

input:

10 7 1
8 3

output:

2

result:

ok answer is '2'

Test #2:

score: 0
Accepted
time: 251ms
memory: 82572kb

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: 251ms
memory: 82400kb

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: 211ms
memory: 82476kb

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: -100
Wrong Answer
time: 211ms
memory: 82504kb

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:

20

result:

wrong answer expected '16', found '20'