QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#600548 | #9132. Painting Fences | ANIG# | WA | 19ms | 148624kb | C++14 | 1.8kb | 2024-09-29 17:14:50 | 2024-09-29 17:14:51 |
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,dp[M][M],dy1[N],dy2[N];
vector<int>p[N],tmp[N];
bitset<N>q[M],nw;
set<int>jl;
multiset<int>rs;
map<int,int>f1[N],f2[N];
int lg2(int x){
if(x==0)return -1;
return __lg(x);
}
int gets(int l,int r,int n){
if(l<0)l=1;
if(r>n)r=n;
if(l==1&&r==n)return 0;
if(n==m){
if(f2[l].count(r))return f2[l][r];
return f2[l][r]=min(r<n?gets(l,l+2*(r-l)+1,n):inf,l>1?gets(r-2*(r-l)-1,r,n):inf)+1;
}else{
if(f1[l].count(r))return f1[l][r];
return f1[l][r]=min(r<n?gets(l,l+2*(r-l)+1,n):inf,l>1?gets(r-2*(r-l)-1,r,n):inf)+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++){
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 19ms
memory: 148624kb
input:
4 4 1001 0100 0110 0110
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 147548kb
input:
3 3 000 111 111
output:
2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'