Submission #500977

# Submission time Handle Problem Language Result Execution time Memory
500977 2022-01-01T19:35:48 Z AmirElarbi Furniture (JOI20_furniture) C++14
100 / 100
1419 ms 16004 KB
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e9
#define eps 1e-7
#define eps1 1e-25
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
#define V 450
using namespace std;
const int MOD = 1e9+7;
const int nax = 1005;
short grid[1005][1005],vis[1005][1005];
int cnt[nax*nax];
int n,m;
int mov[4][2] = {{0,1},{1,0},{-1,0},{0,-1}};
int dfs(int x, int y){
    if(x == n && y == m) return 0;
    if(x > n || y > m) return 1;
    if(grid[x][y]==1) return 1;
    if(vis[x][y]) return grid[x][y];
    vis[x][y] = 1;
    grid[x][y] = min(dfs(x+1,y),dfs(x,y+1));
    cnt[x+y]+=(grid[x][y]==0);
    return grid[x][y];
}
void upd(int x, int y){
    for (int i = 0; i < 4; ++i)
    {
        int nx = x + mov[i][0], ny = y + mov[i][1];
        if(nx < 1 || ny < 1 || nx >n || ny > m ||grid[nx][ny] == 1||(nx == 1 && ny == 1)||(nx == n && ny == m)) continue;
        if(grid[nx-1][ny]&& grid[nx][ny-1]){
            grid[nx][ny] = 1;
        }
        if(grid[nx+1][ny] && grid[nx][ny+1]){
            grid[nx][ny] = 1;
        }
        if(grid[nx][ny]){
            cnt[nx+ny]--;
            upd(nx,ny);
        }
    }
}
int main(){
    optimise;
    cin>>n >>m;
    for (int i = 0; i < nax; ++i)
    {
        for (int j = 0; j < nax; ++j)
        {
            grid[i][j] = 1;
        }
    }
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            cin >> grid[i][j];
            if(grid[i][j] == 0) grid[i][j] = 2;
        }
    }
    dfs(1,1);
    grid[n][m] = 0;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = 1; j <= m; ++j)
        {
            if(grid[i][j]==2) 
                grid[i][j] = 1;
        }
    }
    int q;
    cin >>q;
    while(q--){
        int x,y;
        cin >> x >> y;
        if(grid[x][y] == 1){
            cout << 1 << endl;
            continue;
        }
        else if(cnt[x+y] <= 1){
            cout << 0 << endl;
            continue;
        }
        cout << 1 << endl;
        grid[x][y] = 1;
        cnt[x+y]--;
        upd(x,y);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2380 KB Output is correct
2 Correct 5 ms 2508 KB Output is correct
3 Correct 6 ms 2380 KB Output is correct
4 Correct 12 ms 2500 KB Output is correct
5 Correct 13 ms 2528 KB Output is correct
6 Correct 15 ms 2524 KB Output is correct
7 Correct 15 ms 2508 KB Output is correct
8 Correct 16 ms 2508 KB Output is correct
9 Correct 14 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2380 KB Output is correct
2 Correct 5 ms 2508 KB Output is correct
3 Correct 6 ms 2380 KB Output is correct
4 Correct 12 ms 2500 KB Output is correct
5 Correct 13 ms 2528 KB Output is correct
6 Correct 15 ms 2524 KB Output is correct
7 Correct 15 ms 2508 KB Output is correct
8 Correct 16 ms 2508 KB Output is correct
9 Correct 14 ms 2516 KB Output is correct
10 Correct 36 ms 2512 KB Output is correct
11 Correct 9 ms 2380 KB Output is correct
12 Correct 503 ms 4816 KB Output is correct
13 Correct 68 ms 6084 KB Output is correct
14 Correct 1214 ms 13612 KB Output is correct
15 Correct 1232 ms 13880 KB Output is correct
16 Correct 1293 ms 14784 KB Output is correct
17 Correct 1369 ms 15440 KB Output is correct
18 Correct 1372 ms 15124 KB Output is correct
19 Correct 1393 ms 15976 KB Output is correct
20 Correct 1378 ms 16004 KB Output is correct
21 Correct 1419 ms 15928 KB Output is correct