Submission #790149

# Submission time Handle Problem Language Result Execution time Memory
790149 2023-07-22T11:12:05 Z vjudge1 Furniture (JOI20_furniture) C++17
0 / 100
1 ms 340 KB
//i_love_aisukiuwu
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
	#include "/home/trucmai/.vim/tools.h"
	#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
	#else
	#define debug(x...)
#endif

void open(){
  if(fopen("i.inp","r")){
    freopen("i.inp","r",stdin);
    freopen("o.out","w",stdout);
  }
}

#define ll long long
#define all(a) (a).begin(), (a).end()
#define vi vector<ll>
#define pi pair<ll,ll>
#define pii pair<ll,pair<ll,ll>>
#define fi first
#define se second
#define gcd __gcd
#define mset(a,v) memset(a, v, sizeof(a))
#define endl '\n'
#define spc " "

const int MN1 = 1e6 + 5,MN2 = 1e3 + 5,LOG = 27;
const ll MOD = 1e9 + 7,INF = 1e9;
ll n,m; bool c[MN2][MN2];
ll place[MN1];
ll dx[] = {0,0,1,-1},dy[] = {1,-1,0,0};

bool check(ll x,ll y){
  if((x == 1 && y == 1) || (x == n && y == m)) return false; 
  if((x==n || c[x+1][y]) && (y==m || c[x][y+1])) return true;
  if((x== 1 || c[x-1][y]) && (y==1 || c[x][y-1])) return true; 
  return false;
}

void bfs(ll x,ll y){
  c[x][y] = true; place[x+y]--; 
  for(ll i = 0;i < 4;++i){
    ll nx = x + dx[i],ny = y + dx[y]; 
    if(nx <= 0 || ny <= 0 || nx > n || ny > m || c[nx][ny]) continue; 
    if(check(nx,ny)) bfs(nx,ny);
  }
}

void solve(){
  cin>>n>>m;
  for(ll i = 1;i <= n;++i)
    for(ll j = 1;j <= m;++j){
      place[i+j]++;
      if(c[i][j]){ll tmp; cin>>tmp; continue;}
      cin>>c[i][j]; 
      if(c[i][j]) bfs(i,j);
    } 
  ll q; cin>>q;
  while(q--){ 
    ll x,y; cin>>x>>y;
    if(c[x][y]) cout<<1<<endl; 
    else if(place[x + y]==1) cout<<0<<endl; 
    else{
      bfs(x,y);
      cout<<1<<endl; 
    }
  }
}

signed main(){
  cin.tie(0) -> sync_with_stdio(0);
  open();
  ll t = 1; //cin>>t;
  while(t--) solve(); 
  
  #ifdef LOCAL
    cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  #endif
}

Compilation message

furniture.cpp: In function 'void open()':
furniture.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen("i.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~
furniture.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen("o.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -