QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#671801 | #7733. Cool, It’s Yesterday Four Times More | wangxiaorui# | WA | 32ms | 8792kb | C++14 | 2.4kb | 2024-10-24 14:31:49 | 2024-10-24 14:31:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int X[]={1,0,-1,0};
const int Y[]={0,1,0,-1};
struct node{
int len,xa,ya,xb,yb;
};
vector<node>v1,v2;
char a[1005][1005];
int n,m,f[1005][1005],vis[1005][1005],ans;
bool cmp(node x,node y)
{
return x.len>y.len;
}
void dfs(int x,int y)
{
vis[x][y]=1;
ans++;
for(int i=0;i<4;i++)
{
int x_=x+X[i],y_=y+Y[i];
if(x_<1||y_<1||x_>n||y_>m||vis[x_][y_]||a[x_][y_]=='O') continue;
dfs(x_,y_);
}
}
void sol()
{
cin>>n>>m;
int x=0,xa,ya;
ans=0;
v1.clear();
v2.clear();
memset(f,0,sizeof(f));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>a[i][j];
if(a[i][j]=='.')
{
if(!x) xa=i,ya=j;
x++;
}
else if(a[i][j]=='O')
{
if(x) v1.push_back({x,xa,ya,i,j-1});
x=0;
}
}
if(x) v1.push_back({x,xa,ya,i,m}),x=0;
}
for(int j=1;j<=m;j++)
{
for(int i=1;i<=n;i++)
{
if(a[i][j]=='.')
{
if(!x) xa=i,ya=j;
x++;
}
else if(a[i][j]=='O')
{
if(x) v2.push_back({x,xa,ya,i-1,j});
x=0;
}
}
if(x) v2.push_back({x,xa,ya,n,j}),x=0;
}
sort(v1.begin(),v1.end(),cmp);
sort(v2.begin(),v2.end(),cmp);
if(v1.empty()||v1.size()>1&&v1[0].len==v1[1].len&&v2.size()>1&&v2[0].len==v2[1].len)
{
cout<<0<<endl;
return;
}
if(v1.size()>1&&v1[0].len==v1[1].len) goto p;
for(int i=v1[0].xa;i<=v1[0].xb;i++)
{
for(int j=v1[0].ya;j<=v1[0].yb;j++)
{
// cerr<<i<<' '<<j<<endl;
f[i][j]=1;
}
}
p:;
if(v2.size()>1&&v2[0].len==v2[1].len) goto p2;
for(int i=v2[0].xa;i<=v2[0].xb;i++)
{
for(int j=v2[0].ya;j<=v2[0].yb;j++)
{
// cerr<<i<<' '<<j<<endl;
f[i][j]=1;
}
}
p2:;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(a[i][j]=='O'||vis[i][j]) continue;
if(f[i][j]) dfs(i,j);
}
}
cout<<ans<<endl;
}
int main()
{
int t;
cin>>t;
while(t--) sol();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 8792kb
input:
4 2 5 .OO.. O..O. 1 3 O.O 1 3 .O. 2 3 OOO OOO
output:
3 1 0 0
result:
ok 4 lines
Test #2:
score: -100
Wrong Answer
time: 32ms
memory: 7672kb
input:
200 2 4 OOO. OO.. 2 3 OOO .O. 3 3 O.O OOO OO. 4 1 . . O O 1 2 .O 1 1 . 2 5 .OO.. .O.O. 2 1 O O 1 1 O 1 3 .OO 5 1 O O . O . 5 2 O. .. O. .O .. 5 3 ... ... .OO ..O OOO 3 5 ..O.O .O.O. .OO.O 5 2 .O OO O. O. .. 2 1 O O 3 5 .O.OO O...O ..OO. 1 5 ..... 5 1 O . O . . 5 3 OOO OO. .OO OO. O.O 2 1 O . 5 2 O. ...
output:
3 0 0 2 0 0 2 0 0 0 0 3 3 0 2 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 5th lines differ - expected: '1', found: '0'