Submission #294813

#TimeUsernameProblemLanguageResultExecution timeMemory
294813arman_ferdousFurniture (JOI20_furniture)C++17
100 / 100
469 ms6400 KiB
#include <bits/stdc++.h> using namespace std; // #define DEBUG #define fi first #define se second #define pb push_back #define sz(v) (int)v.size() #define all(v) v.begin(),v.end() #define dbg(x) cerr << #x << " is " << x << "\n"; using ll = long long; using ii = pair<ll,ll>; const int N = 1010; int n, m; int a[N][N]; bool ok(int r, int c) { if(a[r][c] != 0) return true; if(a[r + 1][c - 1] == 3 && a[r - 1][c + 1] == 2) return false; return true; } int dx[] = {-1, 0, 1, 1, 1, 0, -1, -1, -1}; int dy[] = {-1, -1, -1, 0, 1, 1, 1, 0, -1}; void add(int r, int c, int ty) { if(a[r][c] > 1) return; assert(ok(r, c)); a[r][c] = ty; if(a[r - 1][c + 1] == 2 || ty == 2) { a[r][c] = 2; add(r - 1, c, 2); add(r, c + 1, 2); for(int k = 0; k < 5; k++) { int tx = r + dx[k], ty = c + dy[k]; if(a[tx][ty] == 1) add(tx, ty, 2); } } else if(a[r + 1][c - 1] == 3 || ty == 3) { a[r][c] = 3; add(r, c - 1, 3); add(r + 1, c, 3); for(int k = 4; k < 9; k++) { int tx = r + dx[k], ty = c + dy[k]; if(a[tx][ty] == 1) add(tx, ty, 3); } } } void show() { #ifndef DEBUG return; #endif cout << "-----\n"; for(int i = 0; i <= n + 1; i++) { for(int j = 0; j <= m + 1; j++) cout << a[i][j] << " "; cout << endl; } cout << "-----\n"; } int main() { scanf("%d %d", &n, &m); for(int i = 1; i <= n; i++) a[i][0] = 3, a[i][m + 1] = 2; for(int j = 1; j <= m; j++) a[0][j] = 2, a[n + 1][j] = 3; a[0][m + 1] = 2, a[n + 1][0] = 3; show(); for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { int x; scanf("%d", &x); if(x == 1) { add(i, j, 1); } } } show(); int q; scanf("%d", &q); while(q--) { int r, c; scanf("%d %d", &r, &c); if(!ok(r, c)) puts("0"); else { puts("1"); add(r, c, 1); } show(); } return 0; }

Compilation message (stderr)

furniture.cpp: In function 'int main()':
furniture.cpp:70:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   70 |   scanf("%d %d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~~
furniture.cpp:79:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   79 |       int x; scanf("%d", &x);
      |              ~~~~~^~~~~~~~~~
furniture.cpp:86:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   86 |   int q; scanf("%d", &q);
      |          ~~~~~^~~~~~~~~~
furniture.cpp:88:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   88 |     int r, c; scanf("%d %d", &r, &c);
      |               ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...