Submission #500976

# Submission time Handle Problem Language Result Execution time Memory
500976 2022-01-01T19:35:00 Z AmirElarbi Furniture (JOI20_furniture) C++14
5 / 100
441 ms 8852 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];
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 6 ms 2472 KB Output is correct
3 Correct 6 ms 2380 KB Output is correct
4 Correct 13 ms 2508 KB Output is correct
5 Correct 13 ms 2580 KB Output is correct
6 Correct 16 ms 2604 KB Output is correct
7 Correct 16 ms 2512 KB Output is correct
8 Correct 16 ms 2596 KB Output is correct
9 Correct 16 ms 2596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2380 KB Output is correct
2 Correct 6 ms 2472 KB Output is correct
3 Correct 6 ms 2380 KB Output is correct
4 Correct 13 ms 2508 KB Output is correct
5 Correct 13 ms 2580 KB Output is correct
6 Correct 16 ms 2604 KB Output is correct
7 Correct 16 ms 2512 KB Output is correct
8 Correct 16 ms 2596 KB Output is correct
9 Correct 16 ms 2596 KB Output is correct
10 Correct 36 ms 2724 KB Output is correct
11 Correct 11 ms 2388 KB Output is correct
12 Incorrect 441 ms 8852 KB Output isn't correct
13 Halted 0 ms 0 KB -