QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#508915#1819. Cleaning RobotWaterSunWA 71ms106404kbC++143.9kb2024-08-07 21:52:172024-08-07 21:52:17

Judging History

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

  • [2024-08-07 21:52:17]
  • 评测
  • 测评结果:WA
  • 用时:71ms
  • 内存:106404kb
  • [2024-08-07 21:52:17]
  • 提交

answer

#include <bits/stdc++.h>
#define re register
#define get(x,y) (m * (x - 1) + y)

using namespace std;

const int N = 3e6 + 10;
int n,m,k,typ,L;
int dx[] = {0,1,-1,0,0};
int dy[] = {0,0,0,1,-1};
int sum[N],c[N];
bool st[N],vis[N];

inline int read(){
    int r = 0,w = 1;
    char c = getchar();
    while (c < '0' || c > '9'){
        if (c == '-') w = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9'){
        r = (r << 3) + (r << 1) + (c ^ 48);
        c = getchar();
    }
    return r * w;
}

inline void dfs1(int x,int y){
    vis[get(x,y)] = true;
    for (re int i = 1;i <= 4;i++){
        int tx = x + dx[i];
        int ty = y + dy[i];
        if (1 <= tx && tx <= n && 1 <= ty && ty <= m && !st[get(tx,ty)] && !vis[get(tx,ty)]) dfs1(tx,ty);
    }
}

inline int getsum(int x,int y,int xx,int yy){
    int tmp = sum[get(xx,yy)];
    if (x > 1) tmp -= sum[get(x - 1,yy)];
    if (y > 1) tmp -= sum[get(xx,y - 1)];
    if (x > 1 && y > 1) tmp += sum[get(x - 1,y - 1)];
    return tmp;
}

inline void dfs2(int x,int y){
    vis[get(x,y)] = true;
    int xx = x + L - 1,yy = y + L - 1;
    // cerr << x << " " << y << " " << xx << " " << yy << " ???\n";
    c[get(x,y)]++;
    if (xx + 1 <= n && yy + 1 <= m) c[get(xx + 1,yy + 1)]++;
    if (xx + 1 <= n) c[get(xx + 1,y)]--;
    if (yy + 1 <= m) c[get(x,yy + 1)]--;
    for (re int i = 1;i <= 4;i++){
        int tx = x + dx[i];
        int ty = y + dy[i];
        if (1 <= tx && tx <= n && 1 <= ty && ty <= m && !vis[get(tx,ty)]){
            int hx = tx + L - 1;
            int hy = ty + L - 1;
            if (1 <= hx && hx <= n && 1 <= hy && hy <= m && !getsum(tx,ty,hx,hy)) dfs2(tx,ty);
        }
    }
}

inline bool check(int len){
    L = len;
    fill(c + 1,c + n * m + 1,0);
    fill(vis + 1,vis + n * m + 1,false);
    for (re int i = 1;i + len - 1 <= n;i++){
        for (re int j = 1;j + len - 1 <= m;j++){
            int x = i + len - 1,y = j + len - 1;
            if (!getsum(i,j,x,y)){
                dfs2(i,j); goto End;
            }
        }
    }
    End:;
    // for (re int i = 1;i <= n;i++){
    //     for (re int j = 1;j <= m;j++) cerr << c[get(i,j)] << " ";
    //     cerr << "\n";
    // }
    for (re int i = 1;i <= n;i++){
        for (re int j = 1;j <= m;j++){
            int tmp = c[get(i,j)];
            if (i > 1) tmp += c[get(i - 1,j)];
            if (j > 1) tmp += c[get(i,j - 1)];
            if (i > 1 && j > 1) tmp -= c[get(i - 1,j - 1)];
            // cerr << i << " " << j << " " << tmp << " ???\n";
            c[get(i,j)] = tmp;
            // cerr << i << " " << j << " " << c[get(i,j)] << " " << c[get(i - 1,j)] << " " << c[get(i,j - 1)] << " " << c[get(i - 1,j - 1)] << " ???\n";
            if (!st[get(i,j)] && !tmp) return false;
        }
        // cerr << "\n";
    }
    return true;
}

int main(){
    n = read(),m = read(),k = read();
    for (re int i = 1,x,y;i <= k;i++){
        x = read(),y = read();
        st[get(x,y)] = true;
    }
    for (re int i = 1;i <= n;i++){
        for (re int j = 1;j <= m;j++){
            if (!st[get(i,j)]){
                dfs1(i,j); goto End;
            }
        }
    }
    End:;
    for (re int i = 1;i <= n;i++){
        for (re int j = 1;j <= m;j++){
            if (!st[get(i,j)] && !vis[get(i,j)]) return puts("-1"),0;
        }
    }
    for (re int i = 1;i <= n;i++){
        for (re int j = 1;j <= m;j++){
            int tmp = st[get(i,j)];
            if (i > 1) tmp += sum[get(i - 1,j)];
            if (j > 1) tmp += sum[get(i,j - 1)];
            if (i > 1 && j > 1) tmp -= sum[get(i - 1,j - 1)];
            sum[get(i,j)] = tmp;
        }
    }
    // cout << check(3); return;
    int l = 1,r = min(n,m);
    while (l < r){
        int mid = l + r + 1 >> 1;
        if (check(mid)) l = mid;
        else r = mid - 1;
    }
    printf("%d\n",l);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 9948kb

input:

10 7 1
8 3

output:

2

result:

ok answer is '2'

Test #2:

score: -100
Wrong Answer
time: 71ms
memory: 106404kb

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:

wrong answer expected '1', found '-1'