#include <iostream>
#include <vector>
using namespace std;
int n;
int m;
vector <vector <int>> store;
vector<int> emptyd;
void change(int i1,int i2)
{
store[i1][i2] = 1;
emptyd[i1+i2]--;
if (i1<n-1 && i2 >0)
{
if (store[i1+1][i2-1] == 1)
{
if (store[i1+1][i2] == 0)
{
change(i1+1,i2);
}
if (store[i1][i2-1] == 0)
{
change(i1,i2-1);
}
}
}
if (i1 > 0 && i2<m-1)
{
if (store[i1-1][i2+1] == 1)
{
if (store[i1-1][i2] == 0)
{
change(i1-1,i2);
}
if (store[i1][i2+1]==0)
{
change(i1,i2+1);
}
}
}
if(i1 == n-1 && i2 > 0&&store[i1][i2-1] == 0)
{
change(i1,i2-1);
}
if(i1 > 0 && i2 == m-1&&store[i1-1][i2] == 0)
{
change(i1-1,i2);
}
}
int main()
{
cin>>n>>m;
for(int i = 0;i<m;i++)
{
emptyd.push_back(min(n,i+1));
}
for(int i = m;i<m+n-1;i++)
{
emptyd.push_back(min(m,m+n-1-i));
}
vector<int> t;
for(int j = 0;j<m;j++)
{
t.push_back(0);
}
for(int i = 0;i<n;i++)
{
store.push_back(t);
}
int cu;
for(int i = 0;i<n;i++)
{
for (int j = 0;j<m;j++)
{
cin>>cu;
if(cu==1)
{
change(i,j);
}
}
}
int Q;
cin>>Q;
int x,y;
for(int i = 0; i<Q;i++)
{
cin>>x>>y;
x--;
y--;
if(emptyd[x+y]<=1)
{
cout<<0<<"\n";
}
else
{
cout<<1<<"\n";
change(x,y);
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
4 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
4 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |