QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#89810#1283. Paper-cuttingAFewSunsWA 166ms51444kbC++143.8kb2023-03-21 14:41:172023-03-21 14:41:18

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-21 14:41:18]
  • 评测
  • 测评结果:WA
  • 用时:166ms
  • 内存:51444kb
  • [2023-03-21 14:41:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	ll my_pow(ll a,ll b,ll mod){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res=(res*a)%mod;
			a=(a*a)%mod;
			b>>=1;
		}
		return res;
	}
	ll qpow(ll a,ll b){
		ll res=1;
		if(!b) return 1;
		while(b){
			if(b&1) res*=a;
			a*=a;
			b>>=1;
		}
		return res;
	}
	#define db double
	#define pf printf
	#define pc putchar
	#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define enter pc('\n')
	#define space pc(' ')
	#define fir first
	#define sec second
	#define MP make_pair
	#define il inline
	#define inf 8e18
	#define random(x) rand()*rand()%(x)
	#define inv(a,mod) my_pow((a),(mod-2),(mod))
	il ll read(){
		ll sum=0,f=1;
		char ch=0;
		while(!isdigit(ch)){
			if(ch=='-') f=-1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch^48);
			ch=getchar();
		}
		return sum*f;
	}
	il void write(ll x){
		if(x<0){
			x=-x;
			pc('-');
		}
		if(x>9) write(x/10);
		pc(x%10+'0');
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
	il void writesp(ll x){
		write(x);
		space;
	}
}
using namespace my_std;
vector<ll> a[1000010],ck[1000010];
ll T,n,m,cnt=0,f[2000020],ans=inf;
char s[1000010],t[2000020];
bl ckl[1000010],ckr[1000010],cku[1000010],ckd[1000010];
struct node{
	ll l,r,d,u;
}p[1000010];
void init(ll N){
	ll len=2*N+2;
	t[0]='*';
	t[len]='&';
	fr(i,1,len-1){
		if(i%2==0) t[i]=s[i/2];
		else t[i]='%';
	}
	ll maxx=0,mid=0;
	fr(i,1,len){
		if(i<maxx) f[i]=min(f[2*mid-i],maxx-i);
		else f[i]=1;
		while(t[i-f[i]]==t[i+f[i]]) f[i]++;
		if(maxx<i+f[i]){
			mid=i;
			maxx=i+f[i];
		}
	}
}
void dfs(ll x,ll y){
	ck[x][y]=1;
	p[cnt].l=min(p[cnt].l,y);
	p[cnt].r=max(p[cnt].r,y);
	p[cnt].u=min(p[cnt].u,x);
	p[cnt].d=max(p[cnt].d,x);
	if(x>1&&!a[x-1][y]&&!ck[x-1][y]) dfs(x-1,y);
	if(x<n&&!a[x+1][y]&&!ck[x+1][y]) dfs(x+1,y);
	if(y>1&&!a[x][y-1]&&!ck[x][y-1]) dfs(x,y-1);
	if(y<m&&!a[x][y+1]&&!ck[x][y+1]) dfs(x,y+1);
}
void solve(ll dx,ll dy){
	fr(i,1,n) fr(j,1,m) ck[i][j]=0;
	fr(i,1,cnt){
		ck[p[i].u][p[i].l]++;
		ck[p[i].d+1-dx][p[i].l]--;
		ck[p[i].u][p[i].r+1-dy]--;
		ck[p[i].d+1-dx][p[i].r+1-dy]++;
	}
	fr(i,1,n) fr(j,1,m) ck[i][j]+=ck[i][j-1]+ck[i-1][j]-ck[i-1][j-1];
	fr(i,1,n) fr(j,1,m) ck[i][j]+=ck[i][j-1]+ck[i-1][j]-ck[i-1][j-1];
	ll d=0,r=0;
	fr(u,1,n){
		if(!cku[u]) continue;
		if(d<u) d=u;
		while(d<n&&!ckd[d]) d++;
		if(!ckd[d]) break;
		r=0;
		fr(l,1,m){
			if(!ckl[l]) continue;
			if(r<l) r=l;
			while(r<m&&!ckr[r]) r++;
			if(!ckr[r]) break;
			if(a[u][l]==inf) a[u][l]=0;
			if(dx^dy) a[u][l]-=ck[d-dx][r-dy]-ck[u-1][r-dy]-ck[d-dx][l-1]+ck[u-1][l-1];
			else a[u][l]+=ck[d-dx][r-dy]-ck[u-1][r-dy]-ck[d-dx][l-1]+ck[u-1][l-1];
		}
	}
}
void clr(){
	fr(i,1,m) ckl[i]=ckr[i]=0;
	fr(i,1,n) cku[i]=ckd[i]=0;
	fr(i,0,n+1) a[i].clear();
	fr(i,0,n+1) ck[i].clear();
	ans=inf;
	cnt=0;
}
int main(){
	T=read();
	while(T--){
		n=read();
		m=read();
		fr(i,0,n+1) a[i].resize(m+2);
		fr(i,0,n+1) ck[i].resize(m+2);
		fr(i,1,n) cku[i]=ckd[i]=1;
		fr(i,1,m) ckl[i]=ckr[i]=1;
		fr(i,1,n){
			scanf("%s",s+1);
			fr(j,1,m) a[i][j]=s[j]-'0';
			init(m);
			fr(j,1,m) ckl[j]&=((f[2*j-1]-1)/2==(j-1));
			fr(j,1,m) ckr[j]&=((f[2*j+1]-1)/2==(m-j));
		}
		fr(j,1,m){
			fr(i,1,n) s[i]=a[i][j]+'0';
			init(n);
			fr(i,1,n) cku[i]&=((f[2*i-1]-1)/2==(i-1));
			fr(i,1,n) ckd[i]&=((f[2*i+1]-1)/2==(n-i));
		}
		fr(i,1,n){
			fr(j,1,m){
				if(!ck[i][j]&&!a[i][j]){
					p[++cnt]=(node){j,j,i,i};
					dfs(i,j);
				}
			}
		}
		fr(i,1,n) fr(j,1,m) a[i][j]=inf;
		solve(0,0);
		solve(1,0);
		solve(0,1);
		solve(1,1);
		fr(i,1,n) fr(j,1,m){
			ans=min(ans,a[i][j]);
		}
		writeln(ans);
		clr();
	}
}

详细

Test #1:

score: 100
Accepted
time: 8ms
memory: 51444kb

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: 166ms
memory: 50460kb

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
2
1
1
1
0
1
0
2
1
1
1
1
2
1
0
2
2
3
1
2
1
3
2
1
0
1
1
1
2
1
2
1
1
1
1
2
0
1
1
1
1
1
1
1
1
0
3
2
1
3
1
1
3
1
1
1
2
1
1
1
1
1
3
1
1
2
0
2
1
1
2
2
1
2
1
1
2
2
1
2
2
3
2
1
1
1
1
2
1
2
1
1
1
1
1
1
0
1
2
2
2
1
1
5
1
1
1
2
1
1
2
2
3
2
2
1
1
1
2
2
2
1
1
2
2
1
3
1
1
2
1
...

result:

wrong answer 37th words differ - expected: '2', found: '3'