Submission #500918

# Submission time Handle Problem Language Result Execution time Memory
500918 2022-01-01T16:26:28 Z AmirElarbi Furniture (JOI20_furniture) C++14
0 / 100
4 ms 460 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 = 1000005;
bool 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-1 && y == m-1) return 0;
    if(x >= n || y >= m) return 1;
    if(grid[x][y]) 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-1 || ny >= m-1 ||grid[nx][ny] == 1||(nx == 0 && ny == 0)||(nx == n-1 && ny == m-1)) continue;
        cout << nx << " " << ny << endl;
        if(grid[nx-1][ny] == 1 && grid[nx][ny-1] == 1){
            grid[nx][ny] = 1;
        }
        if(grid[nx+1][ny] == 1 && grid[nx][ny+1] == 1){
            grid[nx][ny] = 1;
        }
        if(grid[nx][ny] == 1){
            cnt[nx+ny]--;
            upd(nx,ny);
        }
    }
}
int main(){
    optimise;
    cin>>n >>m;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            cin >> grid[i][j];
        }
    }
    for (int i = 1; i < m; ++i)
    {
        if(grid[0][i-1] == 1) 
            grid[0][i] =1;
    }
    for (int i = 1; i < n; ++i)
    {
        for (int j = 1; j < m; ++j)
        {
            if(grid[i-1][j]==1 && grid[i][j-1] == 1) 
                grid[i][j] = 1;
        }
    }

    dfs(0,0);
    int q;
    cin >>q;
    while(q--){
        int x,y;
        cin >> x >> y;
        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 Incorrect 4 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -