QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#760679 | #9132. Painting Fences | DaiRuiChen007 | WA | 8ms | 39104kb | C++17 | 1.3kb | 2024-11-18 18:20:43 | 2024-11-18 18:20:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int MAXS=1e6+5,MAXN=1005;
int len[MAXN][12],lg[MAXS],st[MAXN][12];
string s[MAXS];
int bit(int x) { return 1<<x; }
int qry(int l,int r) {
int k=__lg(r-l+1);
return min(st[l][k],st[r-bit(k)+1][k]);
}
signed main() {
int n,m;
ios::sync_with_stdio(false);
cin>>n>>m;
if(n<m) {
swap(n,m);
for(int i=1;i<=n;++i) s[i].resize(m+1);
for(int j=1;j<=m;++j) for(int i=1;i<=n;++i) cin>>s[i][j];
} else {
for(int i=1;i<=n;++i) s[i].resize(m+1);
for(int i=1;i<=n;++i) for(int j=1;j<=m;++j) cin>>s[i][j];
}
for(int i=1,k=0;i<=n;++i) {
while((1<<k)<i) ++k;
lg[i]=k;
}
int K=lg[m];
for(int i=1;i<=m;++i) {
for(int k=0;k<=K;++k) len[i][k]=i+1;
for(int j=1;j<=i;++j) {
int k=lg[(m-i+j-1)/j+(i+j-1)/j];
len[i][k]=min(len[i][k],j);
}
}
int ans=lg[n]+lg[m];
for(int t=1;t<=n;++t) {
for(int i=1;i<=m;++i) st[i][0]=(s[t][i]=='1')?st[i][0]+1:0;
for(int k=1;k<=K;++k) for(int i=1;i+bit(k)-1<=m;++i) {
st[i][k]=min(st[i][k-1],st[i+bit(k-1)][k-1]);
}
for(int i=1;i<=m;++i) {
int *v=len[i];
for(int w=0;w<=K;++w) if(v[w]<=i) {
int j=qry(i-v[w]+1,i);
if(j) ans=min(ans,w+lg[(t+j-1)/j+(n-t+j-1)/j]);
}
}
}
printf("%d\n",ans);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 6ms
memory: 36040kb
input:
4 4 1001 0100 0110 0110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 35584kb
input:
3 3 000 111 111
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 4ms
memory: 35848kb
input:
4 3 011 011 001 110
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 0ms
memory: 35988kb
input:
4 4 0011 1111 1111 1111
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 7ms
memory: 36300kb
input:
4 4 0000 0010 0100 1000
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 4ms
memory: 35844kb
input:
2 5 00010 00111
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 8ms
memory: 36740kb
input:
5 5 11111 11111 11111 01111 11111
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 8ms
memory: 36168kb
input:
5 5 00101 00000 00001 00000 00100
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 0ms
memory: 36308kb
input:
5 5 00000 00000 00001 10000 00000
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 0ms
memory: 39104kb
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: 3ms
memory: 37132kb
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: 4ms
memory: 36940kb
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: 36048kb
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: 7ms
memory: 35220kb
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: 8ms
memory: 36724kb
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'