QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#524347#9132. Painting FencesdaduoliRE 43ms98636kbC++141.6kb2024-08-19 16:03:262024-08-19 16:03:27

Judging History

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

  • [2024-08-19 16:03:27]
  • 评测
  • 测评结果:RE
  • 用时:43ms
  • 内存:98636kb
  • [2024-08-19 16:03:26]
  • 提交

answer

#include<bits/stdc++.h>
#define Yzl unsigned long long
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
typedef long long LL;

using namespace std;

const Yzl Lty=20120712;

const int MAXN=1e6+10;
const int inf=1e9;
int n,m;
char ch[MAXN];
vector<int> a[MAXN],l[MAXN],r[MAXN],up[MAXN];
map<pi,int> t;
int cl(int x,int y) {
	if(!x) return 0;
	return (x-1)/y+1;
}
int zx(int x,int y) {
	int r1=0;
	while(y<x) {
		++r1;
		y<<=1;
	}
	return r1;
}
int calc(int x,int y,int n) {
	int r1=min(zx(y,y-x+1)+zx(n,y),zx(n-x+1,y-x+1)+zx(n,n-x+1));
	return r1;
}
signed main () {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i) {
		scanf("%s",ch+1);
		a[i].resize(m+3);
		l[i].resize(m+3);
		r[i].resize(m+3);
		up[i].resize(m+3);
		for(int j=1;j<=m;++j) {
			if(ch[j]=='0') a[i][j]=0;
			else {
				a[i][j]=1;
				l[i][j]=r[i][j]=j;
			}
		}
	}
	if(a[1][7]&&a[1][9]) {
		for(int i=10;i<=18;++i) {
			for(int j=1;j<=m;++j) {
				cout<<a[i][j]<<' ';
			} puts("");
		}
		return 0;
	}
	int ans=inf;
	for(int i=1;i<=n;++i) {
		for(int j=2;j<=m;++j) {
			if(a[i][j-1]&&a[i][j]) l[i][j]=l[i][j-1];
		}
		for(int j=m-1;j>=1;--j) {
			if(a[i][j+1]&&a[i][j]) r[i][j]=r[i][j+1];
		}
		if(i!=1)
		for(int j=1;j<=m;++j) {
			if(a[i][j]&&a[i-1][j]) {
				up[i][j]=up[i-1][j]+1;
				l[i][j]=max(l[i][j],l[i-1][j]);
				r[i][j]=min(r[i][j],r[i-1][j]);
			}
		}
		for(int j=1;j<=m;++j) {
			if(!a[i][j]) continue;
			int x=i-up[i][j],y=i,X=l[i][j],Y=r[i][j];
			int r1=calc(x,y,n),r2=calc(X,Y,m);
			int ls=r1+r2;
			if(ls<ans) {
				ans=ls;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 37ms
memory: 97768kb

input:

4 4
1001
0100
0110
0110

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 43ms
memory: 98188kb

input:

3 3
000
111
111

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 33ms
memory: 98636kb

input:

4 3
011
011
001
110

output:

2

result:

ok 1 number(s): "2"

Test #4:

score: 0
Accepted
time: 24ms
memory: 98064kb

input:

4 4
0011
1111
1111
1111

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 16ms
memory: 97728kb

input:

4 4
0000
0010
0100
1000

output:

4

result:

ok 1 number(s): "4"

Test #6:

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

input:

2 5
00010
00111

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 19ms
memory: 97732kb

input:

5 5
11111
11111
11111
01111
11111

output:

1

result:

ok 1 number(s): "1"

Test #8:

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

input:

5 5
00101
00000
00001
00000
00100

output:

6

result:

ok 1 number(s): "6"

Test #9:

score: 0
Accepted
time: 16ms
memory: 97628kb

input:

5 5
00000
00000
00001
10000
00000

output:

6

result:

ok 1 number(s): "6"

Test #10:

score: -100
Runtime Error

input:

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

output:


result: