QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#600508#9132. Painting FencesANIG#WA 12ms59208kbC++141.9kb2024-09-29 17:01:512024-09-29 17:01:51

Judging History

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

  • [2024-09-29 17:01:51]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:59208kb
  • [2024-09-29 17:01:51]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+5,M=1005,inf=1e9;
int n,m,res=inf,f1[N],f2[N],dy1[N],dy2[N];
vector<int>p[N],tmp[N];
bitset<N>q[M],nw;
set<int>jl;
multiset<int>rs;
int fd(int l,int r,int x){
	if(l<0&&r>0)return 1;
	if(l<0)return fd(-r,-l,x);
	return r/x-(l-1)/x;
}
int gets(int l,int r,int n){
	if(l==1&&r==n)return 0;
	if(n==m)return f2[r-l+1]-(fd(l-1,l-(n-dy2[r-l+1]+1),r-l+1)||fd(n-r,dy2[r-l+1]-r,r-l+1));
	return f1[r-l+1]-(fd(l-1,l-(n-dy1[r-l+1]+1),r-l+1)||fd(n-r,dy1[r-l+1]-r,r-l+1));
}
void del(int x){
	auto w=jl.insert(x).first,w1=w,w2=w;
	w1--;w2++;
	int l=(*w1)+1,r=(*w2)-1;
	if(l<=r)rs.erase(rs.find(gets(l,r,m)));
	if(l<x)rs.insert(gets(l,x-1,m));
	if(x<r)rs.insert(gets(x+1,r,m));
}
int gets(){
	return *(rs.begin());
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		f1[i]=1;
		int x=i;
		while(x<n)x<<=1,f1[i]++;
		dy1[i]=x;
	}
	for(int i=1;i<=m;i++){
		f2[i]=1;
		int x=i;
		while(x<m)x<<=1,f2[i]++;
		dy2[i]=x;
	}
	for(int i=1;i<=n;i++){
		p[i].resize(m+1);
		for(int j=1;j<=m;j++){
			char c;
			cin>>c;
			p[i][j]=c-'0';
		}
	}
	if(n>m){
		swap(n,m);
		for(int i=1;i<=n;i++){
			tmp[i].resize(m+1);
			for(int j=1;j<=m;j++)tmp[i][j]=p[j][i];
		}
		for(int i=1;i<=m;i++)p[i].clear();
		for(int i=1;i<=n;i++)p[i]=tmp[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			q[i][j]=p[i][j]^1;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)nw[j]=1;
		jl.clear();rs.clear();
		jl.insert(0);jl.insert(m+1);
		rs.insert(0);
		for(int j=i;j<=n;j++){
			auto g=nw&q[j];
			for(int k=g._Find_first();k<N;k=g._Find_next(k)){
			//	cout<<k<<endl;
				del(k);
				nw[k]=0;
			}
			if(!rs.size())break;
			//cout<<i<<" "<<j<<" "<<n<<" "<<gets(i,j,n)<<" "<<gets()<<endl;
			res=min(res,gets(i,j,n)+gets());
			//cout<<i<<" "<<j<<" "<<res<<endl;
		}
	}
	cout<<res;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 59076kb

input:

4 4
1001
0100
0110
0110

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 4ms
memory: 59132kb

input:

3 3
000
111
111

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 3ms
memory: 57028kb

input:

4 3
011
011
001
110

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 7ms
memory: 59140kb

input:

4 4
0011
1111
1111
1111

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 11ms
memory: 59020kb

input:

4 4
0000
0010
0100
1000

output:

4

result:

ok 1 number(s): "4"

Test #6:

score: 0
Accepted
time: 3ms
memory: 59088kb

input:

2 5
00010
00111

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 7ms
memory: 57040kb

input:

5 5
11111
11111
11111
01111
11111

output:

1

result:

ok 1 number(s): "1"

Test #8:

score: 0
Accepted
time: 0ms
memory: 57056kb

input:

5 5
00101
00000
00001
00000
00100

output:

6

result:

ok 1 number(s): "6"

Test #9:

score: 0
Accepted
time: 3ms
memory: 59016kb

input:

5 5
00000
00000
00001
10000
00000

output:

6

result:

ok 1 number(s): "6"

Test #10:

score: 0
Accepted
time: 3ms
memory: 59096kb

input:

10 10
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111
1111111111

output:

0

result:

ok 1 number(s): "0"

Test #11:

score: 0
Accepted
time: 12ms
memory: 59104kb

input:

10 10
0001000000
0000000000
0000000000
0000000001
0000000001
0000000001
0000000000
0000000000
0000000000
0000000001

output:

6

result:

ok 1 number(s): "6"

Test #12:

score: 0
Accepted
time: 7ms
memory: 59044kb

input:

10 10
1111111110
1111111110
1111111110
1111111110
1111111110
1111100110
1111100010
1111101110
1111101100
1111100000

output:

1

result:

ok 1 number(s): "1"

Test #13:

score: 0
Accepted
time: 7ms
memory: 57072kb

input:

10 10
0000000000
0000001000
0000000000
0000000000
0000000000
0100000000
0000000000
0000000100
0000000000
0000000000

output:

8

result:

ok 1 number(s): "8"

Test #14:

score: 0
Accepted
time: 3ms
memory: 59208kb

input:

30 31
0000000000000000000000000000000
0000000000000000000000000000000
1111111111111110000000000000011
1111111111111110000000000000011
1111111111111110000000000000011
1111111111111111111111111111111
1111111111111111111111111111111
1111111111111111111111111111100
1111111111111111111111111111100
111111...

output:

3

result:

ok 1 number(s): "3"

Test #15:

score: -100
Wrong Answer
time: 7ms
memory: 59204kb

input:

30 31
0000000000000000000000000000000
0000000000000000000000000000000
0000000001000000000000000000000
0000000000000000000000100000000
0000000000000000000100000000000
0000000000000000001000000000000
0000000000000010000000000000000
0000000000000000000000000000000
0000000000000000000000000100110
000000...

output:

9

result:

wrong answer 1st numbers differ - expected: '10', found: '9'