# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1094141 | 2024-09-28T16:23:26 Z | thangdz2k7 | Furniture (JOI20_furniture) | C++17 | 176 ms | 12884 KB |
// author : thembululquaUwU // 3.9.2024 #include <bits/stdc++.h> #define pb push_back #define fi first #define se second #define endl '\n' using namespace std; using ll = long long; using ii = pair <int, int>; using vi = vector <int>; const int N = 1e3 + 5; const int mod = 1e9 + 7; void maxl(auto &a, auto b) {a = max(a, b);} void minl(auto &a, auto b) {a = min(a, b);} bool blocked[N][N]; int n, m, f[N + N]; void block(int x, int y){ f[x + y] --; blocked[x][y] = true; if (blocked[x - 1][y + 1]) { if (!blocked[x][y + 1]) block(x, y + 1); if (!blocked[x - 1][y]) block(x - 1, y); } if (blocked[x + 1][y - 1]) { if (!blocked[x + 1][y]) block(x + 1, y); if (!blocked[x][y - 1]) block(x, y - 1); } } void solve(){ cin >> n >> m; for (int i = 0; i <= m + 1; ++ i) blocked[0][i] = true, blocked[n + 1][i] = true; for (int i = 0; i <= n + 1; ++ i) blocked[i][0] = true, blocked[i][m + 1] = true; for (int i = 1; i <= n; ++ i) for (int j = 1; j <= m; ++ j) ++ f[i + j]; for (int i = 1; i <= n; ++ i) for (int j = 1; j <= m; ++ j){ int a; cin >> a; if (a && !blocked[i][j]) block(i, j); } int q; cin >> q; while (q --){ int x, y; cin >> x >> y; if (blocked[x][y]) { cout << 1 << endl; continue; } if (f[x + y] == 1){ cout << 0 << endl; continue; } cout << 1 << endl; block(x, y); } } int main(){ if (fopen("pqh.inp", "r")){ freopen("pqh.inp", "r", stdin); freopen("pqh.out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t --) solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 604 KB | Output is correct |
3 | Correct | 2 ms | 484 KB | Output is correct |
4 | Correct | 2 ms | 604 KB | Output is correct |
5 | Correct | 3 ms | 604 KB | Output is correct |
6 | Correct | 2 ms | 456 KB | Output is correct |
7 | Correct | 3 ms | 604 KB | Output is correct |
8 | Correct | 3 ms | 600 KB | Output is correct |
9 | Correct | 2 ms | 604 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 604 KB | Output is correct |
3 | Correct | 2 ms | 484 KB | Output is correct |
4 | Correct | 2 ms | 604 KB | Output is correct |
5 | Correct | 3 ms | 604 KB | Output is correct |
6 | Correct | 2 ms | 456 KB | Output is correct |
7 | Correct | 3 ms | 604 KB | Output is correct |
8 | Correct | 3 ms | 600 KB | Output is correct |
9 | Correct | 2 ms | 604 KB | Output is correct |
10 | Correct | 6 ms | 860 KB | Output is correct |
11 | Correct | 2 ms | 604 KB | Output is correct |
12 | Correct | 80 ms | 6120 KB | Output is correct |
13 | Correct | 39 ms | 3256 KB | Output is correct |
14 | Correct | 147 ms | 10924 KB | Output is correct |
15 | Correct | 146 ms | 11084 KB | Output is correct |
16 | Correct | 170 ms | 12112 KB | Output is correct |
17 | Correct | 162 ms | 12560 KB | Output is correct |
18 | Correct | 176 ms | 12128 KB | Output is correct |
19 | Correct | 165 ms | 12880 KB | Output is correct |
20 | Correct | 153 ms | 12824 KB | Output is correct |
21 | Correct | 165 ms | 12884 KB | Output is correct |