QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#730735 | #9132. Painting Fences | ucup-team134 | WA | 2ms | 8508kb | C++14 | 1.5kb | 2024-11-09 21:19:26 | 2024-11-09 21:19:27 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=1000050;
char s[N];
int lg[N];
int n,m,ans=N;
int Solve2(int l,int r,int n){
int sz=r-l+1;
int cnt=lg[(l+sz-1)/sz];
sz=r+1;
cnt+=lg[(n-r-1+sz-1)/sz];
return cnt;
}
int Solve(int l,int r,int n){
return min(Solve2(l,r,n),Solve2(n-r-1,n-l-1,n));
}
void Try(int xl,int xr,int yl,int yr){
if(xl>xr)return;
//printf("Try (%i %i) (%i %i)\n",xl,xr,yl,yr);
ans=min(ans,Solve(xl,xr,n)+Solve(yl,yr,m));
}
int main(){
for(int i=1;i<N;i++)lg[i]=lg[i>>1]+1;
scanf("%i %i",&n,&m);
bool sw=false;
if(n<m)sw=true,swap(n,m);
vector<vector<int>> a(n,vector<int>(m,0));
if(sw){
for(int j=0;j<m;j++){
scanf("%s",s);
for(int i=0;i<n;i++){
a[i][j]=s[i]-'0';
}
}
}else{
for(int i=0;i<n;i++){
scanf("%s",s);
for(int j=0;j<m;j++){
a[i][j]=s[j]-'0';
}
}
}
vector<int> h(m,0);
for(int i=0;i<n;i++){
vector<int> stk;
stk.push_back(-1);
for(int j=0;j<m;j++){
if(a[i][j]==1)h[j]++;
else h[j]=0;
while(stk.size()>1 && h[stk.back()]>=h[j]){
stk.pop_back();
}
stk.push_back(j);
for(int k=0;k+1<stk.size();k++){
Try(i-h[stk[k+1]]+1,i,stk[k]+1,j);
}
}
}
printf("%i\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7732kb
input:
4 4 1001 0100 0110 0110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 2ms
memory: 7692kb
input:
3 3 000 111 111
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 0ms
memory: 7696kb
input:
4 3 011 011 001 110
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 2ms
memory: 8500kb
input:
4 4 0011 1111 1111 1111
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 2ms
memory: 8112kb
input:
4 4 0000 0010 0100 1000
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 0ms
memory: 7916kb
input:
2 5 00010 00111
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 2ms
memory: 8164kb
input:
5 5 11111 11111 11111 01111 11111
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 2ms
memory: 7772kb
input:
5 5 00101 00000 00001 00000 00100
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 2ms
memory: 7980kb
input:
5 5 00000 00000 00001 10000 00000
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 2ms
memory: 7988kb
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: 2ms
memory: 8508kb
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: 2ms
memory: 7684kb
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: 2ms
memory: 7700kb
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: 2ms
memory: 7952kb
input:
30 31 0000000000000000000000000000000 0000000000000000000000000000000 1111111111111110000000000000011 1111111111111110000000000000011 1111111111111110000000000000011 1111111111111111111111111111111 1111111111111111111111111111111 1111111111111111111111111111100 1111111111111111111111111111100 111111...
output:
3
result:
ok 1 number(s): "3"
Test #15:
score: 0
Accepted
time: 2ms
memory: 7692kb
input:
30 31 0000000000000000000000000000000 0000000000000000000000000000000 0000000001000000000000000000000 0000000000000000000000100000000 0000000000000000000100000000000 0000000000000000001000000000000 0000000000000010000000000000000 0000000000000000000000000000000 0000000000000000000000000100110 000000...
output:
10
result:
ok 1 number(s): "10"
Test #16:
score: 0
Accepted
time: 2ms
memory: 7992kb
input:
30 31 0000000000000000000000000000000 0000000011111111111111000000000 0000000011111111111111000000000 1111111111111111111111000000000 1111111111111111111111000000000 1111111111111111111111000000000 1111111111111111111111000111100 1111111111111111111111000111100 1111111111111111111111000111100 111111...
output:
3
result:
ok 1 number(s): "3"
Test #17:
score: -100
Wrong Answer
time: 2ms
memory: 8416kb
input:
30 31 0000001010000000000000000000000 0000000000000000000000000000000 0000000000000000001000000000000 0000010000000000000000000000000 0000000000000000000000000000000 0000000000000000000000000000000 0000001000010000000000000000000 0000100000010010000000000000000 0000000001000001000000010000000 000000...
output:
10
result:
wrong answer 1st numbers differ - expected: '9', found: '10'