QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#619300 | #2446. Block Breaker | AnotherDayofSun# | AC ✓ | 110ms | 8280kb | C++20 | 1.4kb | 2024-10-07 13:48:38 | 2024-10-07 13:48:39 |
Judging History
answer
#include<bits/stdc++.h>
#define N 2005
#define re
#define ll long long
using namespace std;
int n,m,K,q,T;
inline void Rd(int &res){
re char c;res=0;
while(c=getchar(),c<48);
do res=(res<<3)+(res<<1)+(c^48);
while(c=getchar(),c>47);
}
struct node{
int x,y;
};
bool mk[N][N];
void Clear(){
for(int i=0;i<=n;i++)
for(int j=0;j<=m;j++)mk[i][j]=0;
}
node Q[N*N];
bool pd(int x,int y){
if(mk[x][y])return 0;
if(x<1||x>n||y<1||y>m)return 0;
int s= (mk[x-1][y]|mk[x+1][y]) + (mk[x][y-1]|mk[x][y+1]);
return s==2;
}
int Solve(int x,int y){
int l=0,r=0;
Q[++r]=(node){x,y};
mk[x][y]=1;
int ans=1;
while(l<r){
int x=Q[++l].x;
int y=Q[l].y;
if(pd(x-1,y))mk[x-1][y]=1,ans++,Q[++r]=(node){x-1,y};
if(pd(x+1,y))mk[x+1][y]=1,ans++,Q[++r]=(node){x+1,y};
if(pd(x,y-1))mk[x][y-1]=1,ans++,Q[++r]=(node){x,y-1};
if(pd(x,y+1))mk[x][y+1]=1,ans++,Q[++r]=(node){x,y+1};
}
return ans;
}
int main(){
Rd(T);
while(T--){
Rd(n);Rd(m);Rd(K);
while(K--){
int x,y;
scanf("%d%d",&x,&y);
if(mk[x][y]){
puts("0");
continue;
}
int res=Solve(x,y);
printf("%d\n",res);
}
Clear();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 110ms
memory: 8280kb
input:
10 1 1 2 1 1 1 1 1 2 5 1 2 1 2 1 1 1 2 1 1 1651 1852 69820 938 1459 98 243 1504 554 725 245 601 587 1465 1687 1037 1172 433 1112 173 493 1175 278 302 558 1326 633 375 1043 495 1673 1275 1672 1629 1299 1588 432 507 1754 953 270 1475 1805 1343 1096 798 1633 1124 809 525 1163 1201 1633 1381 578 1489 89...
output:
1 0 1 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 576535 lines