QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#90697#1283. Paper-cuttingfansizheWA 38ms3744kbC++141.7kb2023-03-24 19:42:322023-03-24 19:42:34

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-24 19:42:34]
  • 评测
  • 测评结果:WA
  • 用时:38ms
  • 内存:3744kb
  • [2023-03-24 19:42:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
int n,m;
struct Array{
	int a[1000005];
	int* operator [](const int &i){return a+i*m;}
}a,vis;
int len1[1000005],len2[1000005];
int l1,r1,l2,r2;
bool checkr(int i,int j){for(int k=0;k<m;k++)if(a[i][k]!=a[j][k])return 0;return 1;}
bool checkc(int i,int j){for(int k=0;k<n;k++)if(a[k][i]!=a[k][j])return 0;return 1;}
void dfs(int x,int y){
	vis[x][y]=1;
	for(int i=0;i<4;i++){
		int xx=x+dx[i],yy=y+dy[i];
		if(xx>=l1&&xx<=r1&&yy>=l2&&yy<=r2&&a[xx][yy]&&!vis[xx][yy])dfs(xx,yy);
	}
}
int main(){
	int _;scanf("%d",&_);
	while(_--){
		scanf("%d%d",&n,&m);
		for(int i=0;i<n;i++)
			for(int j=0;j<m;j++){
				char c=getchar();
				while(c<'0'||c>'1')c=getchar();
				a[i][j]=c=='0';
				vis[i][j]=0;
			}
		for(int i=0;i<n;i++)len1[i]=0;
		for(int i=0;i<m;i++)len2[i]=0; 
		for(int i=0,mx=0;i<n-1;i++){
			if(mx+len1[mx]>i)len1[i]=(mx*2-i>=0?len1[mx*2-i]:0);
			else len1[i]=0;
			while(i-len1[i]>=0&&i+len1[i]+1<n&&checkr(i-len1[i],i+len1[i]+1))len1[i]++;
			if(i+len1[i]>=mx+len1[mx])mx=i;
		}
		for(int i=0,mx=0;i<m-1;i++){
			if(mx+len2[mx]>i)len2[i]=(mx*2-i>=0?len2[mx*2-i]:0);
			else len2[i]=0;
			while(i-len2[i]>=0&&i+len2[i]+1<m&&checkc(i-len2[i],i+len2[i]+1))len2[i]++;
			if(i+len2[i]>=mx+len2[mx])mx=i;
		}
		l1=0;
		for(int i=0;i<n;i++)if(l1>=i-len1[i]+1)l1=i+1;
		r1=n-1;
		for(int i=n-1;i>=l1;i--)if(r1<=i+len1[i])r1=i;
		l2=0;
		for(int i=0;i<m;i++)if(l2>=i-len2[i]+1)l2=i+1;
		r2=m-1;
		for(int i=m-1;i>=l2;i--)if(r2<=i+len2[i])r2=i;
		int cnt=0;
		for(int i=l1;i<=r1;i++)
			for(int j=l2;j<=r2;j++)if(a[i][j]&&!vis[i][j])dfs(i,j),cnt++; 
		printf("%d\n",cnt);
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 3744kb

input:

3
2 5
11001
11001
5 7
1001100
0110011
0101101
0010010
1000000
3 2
11
11
11

output:

1
4
0

result:

ok 3 tokens

Test #2:

score: -100
Wrong Answer
time: 38ms
memory: 3744kb

input:

100000
3 3
010
101
101
4 2
10
10
10
10
4 2
11
00
00
11
7 1
1
0
0
1
1
0
0
6 1
1
0
0
1
1
1
5 2
11
00
00
11
11
10 1
1
0
0
0
0
0
0
0
0
1
9 1
0
0
0
0
0
0
0
0
0
10 1
1
1
1
1
1
1
1
1
1
0
9 1
0
0
0
0
0
0
1
1
0
1 10
0010000100
7 1
0
0
0
0
0
0
0
4 2
00
00
00
00
7 1
0
1
0
0
0
0
1
10 1
1
0
0
0
0
0
0
0
0
1
9 1
1...

output:

3
1
1
1
1
1
1
1
1
1
2
1
1
2
1
1
1
1
2
1
1
1
1
0
1
0
2
1
1
1
1
2
1
0
2
1
2
1
2
1
2
2
1
0
1
1
1
2
1
1
1
0
1
1
2
0
1
1
0
1
0
1
1
1
0
3
1
1
3
0
0
3
1
1
1
2
1
1
1
1
1
3
1
1
2
0
1
1
1
2
2
1
1
1
1
2
2
1
2
2
3
2
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
2
2
2
1
1
5
1
1
1
2
1
1
2
2
2
2
2
1
1
1
2
2
2
1
1
2
2
1
3
1
1
2
1
...

result:

wrong answer 20th words differ - expected: '2', found: '1'