이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={1,-1,0,0};
int n,m;
vector<pair<bool,pair<int,int>>> updates;
bool tr[1005][1005];///tr[i][j] = 0, daca exista cel putin un drum care trece prin pozitia (i,j)
int cnt[2005];
void completeaza(int x, int y, bool spec)
{
if(tr[x][y] || (x==1 && y==1) || (x==n && y==m))
return;
if(spec || (tr[x-1][y] && tr[x][y-1]) || (tr[x+1][y] && tr[x][y+1]))
{
//cout<<x<<" "<<y<<" "<<spec<<"\n";
tr[x][y]=1;
cnt[x+y]--;
for(int i=0;i<4;i++)
if(!tr[x+dx[i]][y+dy[i]])
completeaza(x+dx[i],y+dy[i],0);
}
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
int a,b;
cin>>n>>m;
for(int i=1;i<=n;i++)
{
tr[i][0]=tr[i][m+1]=1;
for(int j=1;j<=m;j++)
{
cin>>a;
if(a==1)
{
updates.push_back({0,{i,j}});
}
tr[i][j]=0;
tr[0][j]=tr[n+1][j]=1;
cnt[i+j]++;
}
}
int cntq;
cin>>cntq;
for(int i=0;i<cntq;i++)
{
cin>>a>>b;
updates.push_back({1,{a,b}});
}
for(int i=0;i<updates.size();i++)
{
a = updates[i].second.first;
b = updates[i].second.second;
int rez;
if(tr[a][b]==0)///daca exista cel putin un drum care trece
{
if(cnt[a+b]>1)
{
completeaza(a,b,1);
rez=1;
}
else
{
rez=0;
}
}
else
{
rez=1;
}
if(updates[i].first)
{
cout<<rez<<"\n";
///afisare
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
furniture.cpp: In function 'int main()':
furniture.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<bool, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i=0;i<updates.size();i++)
| ~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |