# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1269395 | quangminh412 | Furniture (JOI20_furniture) | C++17 | 156 ms | 10288 KiB |
/*
Ben Watson
stuang Minh MasterDDDDD
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const string name = "test";
void solve();
signed main()
{
if (fopen((name + ".inp").c_str(), "r"))
{
freopen((name + ".inp").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
}
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
return 0;
}
// main program
const int maxn = 1e3 + 2;
int c[maxn][maxn], R[maxn][maxn], cnt[2 * maxn];
int n, m, q;
stack<pair<int, int>> st;
void ins(int u, int v)
{
if (R[u][v] == 1)
return;
R[u][v] = 1;
cnt[u + v]--;
st.push({u, v});
}
int update(int u, int v)
{
if (R[u][v] == 1)
return 1;
if (cnt[u + v] == 1)
return 0;
ins(u, v);
while (!st.empty())
{
int x = st.top().first, y = st.top().second;
st.pop();
if (R[x - 1][y + 1] == 1)
{
ins(x - 1, y);
ins(x, y + 1);
}
if (R[x + 1][y - 1] == 1)
{
ins(x, y - 1);
ins(x + 1, y);
}
}
return 1;
}
void solve()
{
cin >> n >> m;
for (int i = 0; i <= n + 1; i++)
for (int j = 0; j <= m + 1; j++)
R[i][j] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
R[i][j] = 0;
cnt[i + j]++;
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
{
cin >> c[i][j];
if (c[i][j] == 1)
update(i, j);
}
cin >> q;
while (q--)
{
int x, y; cin >> x >> y;
cout << update(x, y) << '\n';
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |