#include<bits/stdc++.h>
#define fo(i,l,r) for(int i = l ; i <= r ; i++)
#define fod(i,r,l) for(int i = r ; i >= l ; i--)
#define pb emplace_back
#define maxn 1000010
#define N 1010
#define int long long
#define ss(x) (int) x.size()
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define vii vector<pii>
#define en cout << "\n";
#define bit(x,i) ((x >> i) & 1)
#define bitcount(x) __builtint_popcount(x)
#define onbit(x,i) (x | (1ll << i))
#define offbit(x,i) (x ^ (1ll << i))
#define inf (int)1e18
#define lb(x) x & (-x)
using namespace std;
int n,m,q;
int r[N][N],cnt[maxn];
int solve(int i,int j)
{
if(r[i][j]) return 1;
if(cnt[i + j] == 1) return 0;
stack<pii> q;
if(!r[i][j])
{
q.emplace(i,j);
r[i][j] = 1;
cnt[i + j]--;
}
while(ss(q))
{
auto [x,y] = q.top();
q.pop();
if(r[x - 1][y + 1])
{
if(!r[x - 1][y])
{
r[x - 1][y] = 1;
cnt[x + y - 1]--;
q.emplace(x - 1,y);
}
if(!r[x][y + 1])
{
r[x][y + 1] = 1;
cnt[x + y + 1]--;
q.emplace(x,y + 1);
}
}
if(r[x + 1][y - 1])
{
if(!r[x][y - 1])
{
r[x][y - 1] = 1;
cnt[x + y - 1]--;
q.emplace(x,y - 1);
}
if(!r[x + 1][y])
{
r[x + 1][y] = 1;
cnt[x + y + 1]--;
q.emplace(x + 1,y);
}
}
}
return 1;
}
main()
{
#define name "TASK"
if(fopen(name".inp","r"))
{
freopen(name".inp","r",stdin);
freopen(name".out","w",stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
fo(i,1,n) fo(j,1,m) cnt[i + j]++;
fo(i,1,n) fo(j,1,m)
{
int x;
cin >> x;
if(x == 1) solve(i,j);
}
cin >> q;
while(q--)
{
int i,j;
cin >> i >> j;
cout << solve(i,j);
en;
}
}
Compilation message
furniture.cpp:70:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
70 | main()
| ^~~~
furniture.cpp: In function 'int main()':
furniture.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | freopen(name".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
furniture.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
76 | freopen(name".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Incorrect |
1 ms |
860 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |