답안 #791103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791103 2023-07-23T12:15:12 Z makanhulia Furniture (JOI20_furniture) C++17
5 / 100
5000 ms 27324 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define endl "\n"
#define pii pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define pque priority_queue
#define pqueg priority_queue<ll,vector<ll>,greater<ll>>
#define que queue<ll>
#define FOR(m,i,n) for(int i=(m); i<=(n); i++)
#define FORM(m,i,n) for(int i=(m); i>=(n); i--)
#define all(v) sort(v.begin(),v.end())
ll n,m,qq,x,y;
queue<pii> q;
ll grid[1010][1010],d[1000100];
bool vis[1010][1010];
ll tempd[1000100];
vector<pii> v;
vector<ll> idxV;
bool cek;
void bfs() {
  cek = false;
  while(!q.empty()) {
    pii x = q.front();
    q.pop();
    v.pb({x.fi,x.se});
    d[x.fi+x.se]--;
    if(d[x.fi+x.se] == 0) cek = true;
    if(vis[x.fi+1][x.se-1] && !vis[x.fi+1][x.se] && x.fi < n) 
    {
      q.push({x.fi+1,x.se});
      vis[x.fi+1][x.se] = true;
    }
    if(vis[x.fi+1][x.se-1] && !vis[x.fi][x.se-1] && x.fi < n) {
      q.push({x.fi,x.se-1});
      vis[x.fi][x.se-1] = true;
    }
    if(vis[x.fi-1][x.se+1] && !vis[x.fi][x.se+1] && x.se < m) {
      q.push({x.fi,x.se+1});
      vis[x.fi][x.se+1] = true;
    } 
    if(vis[x.fi-1][x.se+1] && !vis[x.fi-1][x.se] && x.se < m) {
      q.push({x.fi-1,x.se});
      vis[x.fi-1][x.se] = true;
    } 
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  FOR(1,i,n) {
    FOR(1,j,m) {
      cin >> grid[i][j];
      vis[i][j] = grid[i][j];
      if(vis[i][j]) q.push({i,j});
      d[i+j]++;
    } 
  }
  FOR(1,i,m) vis[0][i] = true;
  FOR(1,i,n) vis[i][0] = true;
  bfs();
  v.clear();
  cin >> qq;
  while(qq--) {
    cin >> x >> y;
    if(vis[x][y]) {
      cout << 1 << endl;
      continue;
    }
    vis[x][y] = true;
    q.push({x,y});
    bfs();
    if(cek) {
      cout << 0 << endl;
      for(auto i : v) {
        vis[i.fi][i.se] = false;
        d[i.fi+i.se]++;
      }
    }
    else {
      cout << 1 << endl;
    }
    v.clear();
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 2 ms 984 KB Output is correct
4 Correct 3 ms 1108 KB Output is correct
5 Correct 3 ms 1076 KB Output is correct
6 Correct 4 ms 1108 KB Output is correct
7 Correct 4 ms 1236 KB Output is correct
8 Correct 4 ms 1108 KB Output is correct
9 Correct 7 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 2 ms 980 KB Output is correct
3 Correct 2 ms 984 KB Output is correct
4 Correct 3 ms 1108 KB Output is correct
5 Correct 3 ms 1076 KB Output is correct
6 Correct 4 ms 1108 KB Output is correct
7 Correct 4 ms 1236 KB Output is correct
8 Correct 4 ms 1108 KB Output is correct
9 Correct 7 ms 1236 KB Output is correct
10 Correct 31 ms 1880 KB Output is correct
11 Correct 3 ms 900 KB Output is correct
12 Correct 149 ms 16888 KB Output is correct
13 Correct 49 ms 16624 KB Output is correct
14 Correct 271 ms 20664 KB Output is correct
15 Correct 280 ms 19304 KB Output is correct
16 Execution timed out 5046 ms 27324 KB Time limit exceeded
17 Halted 0 ms 0 KB -