Submission #1210094

#TimeUsernameProblemLanguageResultExecution timeMemory
1210094nguynFurniture (JOI20_furniture)C++20
100 / 100
153 ms6452 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define F first #define S second #define pb push_back #define pii pair<int,int> const int N = 1e3 + 5; int vis[N][N], n, m; int d[2 * N]; void block(int x, int y) { d[x + y]--; vis[x][y] = 1; if (vis[x + 1][y - 1] && !vis[x + 1][y]) block(x + 1, y); if (vis[x + 1][y - 1] && !vis[x][y - 1]) block(x, y - 1); if (vis[x - 1][y + 1] && !vis[x - 1][y]) block(x - 1, y); if (vis[x - 1][y + 1] && !vis[x][y + 1]) block(x, y + 1); } signed main(){ ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0) ; if (fopen("INP.INP" ,"r")) { freopen("INP.INP" ,"r" , stdin) ; freopen("OUT.OUT" , "w" , stdout) ; } cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { d[i + j]++; vis[i][j] = 0; } } for (int i = 0; i <= n + 1; i++) { vis[i][0] = 1; vis[i][m + 1] = 1; } for (int i = 0; i <= m + 1; i++) { vis[0][i] = 1; vis[n + 1][i] = 1; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { int c; cin >> c; if (c && !vis[i][j]) { block(i, j); } } } int q; cin >> q; while(q--) { int x, y; cin >> x >> y; if (vis[x][y]) { cout << 1 << '\n'; } else if (d[x + y] == 1) { cout << 0 << '\n'; } else { cout << 1 << '\n'; block(x, y); } } }

Compilation message (stderr)

furniture.cpp: In function 'int main()':
furniture.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen("INP.INP" ,"r" , stdin) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
furniture.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         freopen("OUT.OUT" , "w" , stdout) ;
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...