Submission #784366

# Submission time Handle Problem Language Result Execution time Memory
784366 2023-07-16T04:20:56 Z kebine Furniture (JOI20_furniture) C++17
0 / 100
6 ms 840 KB
#include<bits/stdc++.h>
 
#define sherina ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define int long long
#define INF 1e18
#define endl '\n'
 
using namespace std;

int n , m , c[1003][1003] , q , x , y , aa[1003] , bb[1003] , diag[1003];
set < int > st;
bool vis[1003][1003];

bool inside(int a , int b){
   return 0 < a && a <= n && 0 < b && b <= m;
}

void rec(int x , int y){
    if(!inside(x , y)) return;
    diag[x + y]--;
    c[x][y] = 1;
    vis[x][y] = true;
    if(c[x + 1][y - 1]){
        //cout << x -1 << " " << y - 1<< endl;
        if(!vis[x][y - 1]) rec(x , y - 1);
        if(!vis[x + 1][y]) rec(x + 1 , y);
    }
    if(c[x - 1][y + 1]){
        //cout << x -1 << " " << y + 1<< endl;
        if(!vis[x - 1][y]) rec(x - 1 , y); 
        if(!vis[x][y + 1]) rec(x , y + 1);
    }
}

signed main(){
    cin >> n >> m;
    int id = 1;
    for(int i = 1 ;  i <= n ; i++){
        for(int j = 1 ; j <= m ; j++){
            cin >> c[i][j];
            diag[i + j]++;
        }
    }
    for(int i = 1 ; i <= n ; i++){
        c[i][0] = 1;
        c[i][m + 1] = 1;
    }
    for(int i = 1 ; i <= m ; i++){
        c[0][i] = 1;
        c[n + 1][i] = 1;
    }
    for(int i = 1 ;  i <= n ; i++){
        for(int j = 1 ; j <= m ; j++){
            if(c[i][j]) rec(i , j);
        }
    }
    cin >> q;
    while(q--){
        cin >> x >> y;
        if(c[x][y]){
            cout << "1" << endl;
        }
        else if(diag[x + y] == 1){
            cout << "0" << endl;
        }
        else{
            cout <<"1" << endl;
            rec(x , y);
        }

    }
}

Compilation message

furniture.cpp: In function 'int main()':
furniture.cpp:38:9: warning: unused variable 'id' [-Wunused-variable]
   38 |     int id = 1;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 764 KB Output is correct
2 Incorrect 6 ms 840 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 764 KB Output is correct
2 Incorrect 6 ms 840 KB Output isn't correct
3 Halted 0 ms 0 KB -