QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#619261 | #6150. 拼图 | McIron233 | 100 ✓ | 123ms | 6104kb | C++14 | 2.3kb | 2024-10-07 13:40:44 | 2024-10-07 13:40:46 |
Judging History
answer
#include<bits/stdc++.h>
#define Clr(x) memset(x,0,sizeof(x))
#define x1 Starrykiller
#define x2 Arcaea
#define y1 Minecraft
#define y2 Milmon
#define N 100005
using namespace std;
int n,s,w[N],a[N],sum[N],up[N];
int st[N],ed[N],C,ans;
int id(int x,int y){
if(x<1 || y<1)return 0;
return n*(y-1)+x;
}
int getsum(int x1,int x2,int y1,int y2){
--x1; --y1; return sum[id(x2,y2)]-sum[id(x1,y2)]-sum[id(x2,y1)]+sum[id(x1,y1)];
}
void calc(int L,int R){
for(int i=1;i<=s;++i){
for(int j=st[i],r=0;j<=ed[i];++j){
if(getsum(L,R,j,j)==0)++r;
else r=0; ans=max(ans,(R-L+1)*r);
}
} int lmax[2][2],rmax[2][2],mid=0;
Clr(lmax); Clr(rmax);
for(int i=1;i<=s;++i){
int mxl=0,mxr=0;
for(int j=st[i];j<=ed[i];++j){
if(getsum(L,R,j,j))break;
++mxl;
}
for(int j=ed[i];j>=st[i];--j){
if(getsum(L,R,j,j))break;
++mxr;
}
if(mxl==w[i])mid+=w[i];
else{
if(mxl>lmax[0][0])lmax[0][0]=mxl,lmax[0][1]=i;
else if(mxl>lmax[1][0])lmax[1][0]=mxl,lmax[1][1]=i;
if(mxr>rmax[0][0])rmax[0][0]=mxr,rmax[0][1]=i;
else if(mxr>rmax[1][0])rmax[1][0]=mxr,rmax[1][1]=i;
}
}
for(int p=0;p<2;++p){
for(int q=0;q<2;++q){
if(lmax[p][1]!=rmax[q][1])
ans=max(ans,(R-L+1)*(mid+lmax[p][0]+rmax[q][0]));
}
} ans=max(ans,(R-L+1)*(mid+lmax[0][0]));
ans=max(ans,(R-L+1)*(mid+rmax[0][0]));
}
void Solve(){
//Clear
C=ans=0; Clr(sum); Clr(up);
Clr(ed); Clr(w); Clr(a); Clr(st);
//input and prework
cin>>s>>n;
for(int i=1;i<=s;++i){
cin>>w[i]; st[i]=C+1;
for(int j=1;j<=n;++j){
for(int k=1;k<=w[i];++k){
char ch; cin>>ch;
a[id(j,C+k)]=ch-'0';
}
} C+=w[i]; ed[i]=C;
} int m=sqrt(C*n);
for(int i=1;i<=s;++i){
for(int j=1;j<=n;++j){
for(int k=st[i];k<=ed[i];++k)
sum[id(j,k)]=a[id(j,k)]+sum[id(j-1,k)]+sum[id(j,k-1)]-sum[id(j-1,k-1)];
}
}
for(int j=1;j<=C;++j){
for(int i=1,lst=0;i<=n+1;++i){
if(i>n || a[id(i,j)]){
for(int k=lst+1;k<=i-1;++k)up[id(k,j)]=i-1;
lst=i;
}
}
}
//solver
if(n<=m){
for(int L=1;L<=n;++L){
for(int R=L;R<=n;++R)
calc(L,R);
}
} else {
for(int i=1;i<=n;++i){
for(int j=1;j<=C;++j)
calc(i,up[id(i,j)]);
}
} cout<<ans<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
int Ks; cin>>Ks; while(Ks--)Solve();
return 0;
}
详细
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 5980kb
input:
1 1 30 30 000000000000001000000000000000 000000000000000100000000000000 000000000000101000000010100001 000000000000000000010100000001 000100000000000000000001100000 000001000000000000000000000000 000000000100000000000000000000 000000000000000000000000000000 100000000000000000000000000000 00000100001...
output:
247
result:
ok 1 number(s): "247"
Test #2:
score: 10
Accepted
time: 16ms
memory: 5964kb
input:
1 2 100 89 00000000000000000000000000000001000000000000000000000000000001000000000010000000000000000 00000000000001000010000000011000100000001010000000000000000001000000000000000000000000010 10000000000000000000000000000000000000000000000001010001000000000000000000000000000000000 0000000000001000000...
output:
1554
result:
ok 1 number(s): "1554"
Test #3:
score: 10
Accepted
time: 56ms
memory: 6040kb
input:
1 3 1000 28 0000000000000100000000000000 0000000100000000000000000000 0000100000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 0000000000000000000000000000 000000000000001000000000000...
output:
4224
result:
ok 1 number(s): "4224"
Test #4:
score: 10
Accepted
time: 63ms
memory: 5852kb
input:
1 300 100 5 00001 00101 00000 00000 00010 00000 00000 00000 00000 10000 00000 00000 00000 00000 00010 00000 00100 00010 10000 00000 00000 00000 00000 00000 00001 00000 00100 00000 00000 00000 00000 00000 00000 00000 00000 01001 01000 00100 00000 00000 00000 10001 00000 00000 00100 00000 01000 00000 ...
output:
18360
result:
ok 1 number(s): "18360"
Test #5:
score: 10
Accepted
time: 91ms
memory: 6104kb
input:
3 12 6000 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
17840 27720 15975
result:
ok 3 number(s): "17840 27720 15975"
Test #6:
score: 10
Accepted
time: 53ms
memory: 6000kb
input:
3 12 5000 2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 10 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ...
output:
26850 9570 85430
result:
ok 3 number(s): "26850 9570 85430"
Test #7:
score: 10
Accepted
time: 123ms
memory: 5984kb
input:
3 30 1000 5 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00010 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 00000 ...
output:
9930 90120 13964
result:
ok 3 number(s): "9930 90120 13964"
Test #8:
score: 10
Accepted
time: 120ms
memory: 5988kb
input:
3 9 10000 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 ...
output:
13698 88380 8232
result:
ok 3 number(s): "13698 88380 8232"
Test #9:
score: 10
Accepted
time: 90ms
memory: 5916kb
input:
3 300 100 9 000000000 000000000 000001000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 000000000 00000000...
output:
14706 19680 89240
result:
ok 3 number(s): "14706 19680 89240"
Test #10:
score: 10
Accepted
time: 112ms
memory: 5856kb
input:
3 9000 10 2 00 10 00 00 00 00 00 00 00 00 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 ...
output:
92340 30653 40296
result:
ok 3 number(s): "92340 30653 40296"