QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#600449 | #9132. Painting Fences | ANIG# | WA | 10ms | 52656kb | C++14 | 1.5kb | 2024-09-29 16:37:30 | 2024-09-29 16:37:31 |
Judging History
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;
vector<int>p[N],tmp[N];
bitset<N>q[M],nw;
set<int>jl;
multiset<int>rs;
int gets(int l,int r,int n){
if(l==1&&r==n)return 0;
int k=(n-1)/(r-l+1)+1;
return __lg(k-1)+2-((l-1)%(r-l+1)==0||(n-r)%(r-l+1)==0);
}
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++){
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: 7ms
memory: 51656kb
input:
4 4 1001 0100 0110 0110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 52316kb
input:
3 3 000 111 111
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 10ms
memory: 52464kb
input:
4 3 011 011 001 110
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: 0
Accepted
time: 7ms
memory: 52564kb
input:
4 4 0011 1111 1111 1111
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 3ms
memory: 51452kb
input:
4 4 0000 0010 0100 1000
output:
4
result:
ok 1 number(s): "4"
Test #6:
score: 0
Accepted
time: 7ms
memory: 50640kb
input:
2 5 00010 00111
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 4ms
memory: 52296kb
input:
5 5 11111 11111 11111 01111 11111
output:
1
result:
ok 1 number(s): "1"
Test #8:
score: 0
Accepted
time: 10ms
memory: 52568kb
input:
5 5 00101 00000 00001 00000 00100
output:
6
result:
ok 1 number(s): "6"
Test #9:
score: 0
Accepted
time: 7ms
memory: 52656kb
input:
5 5 00000 00000 00001 10000 00000
output:
6
result:
ok 1 number(s): "6"
Test #10:
score: 0
Accepted
time: 7ms
memory: 51672kb
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: 4ms
memory: 52088kb
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: 3ms
memory: 50616kb
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: 0ms
memory: 51048kb
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: 10ms
memory: 52040kb
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: 4ms
memory: 52192kb
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'