QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#207627 | #6769. Monster Hunter | veg# | WA | 1ms | 5996kb | C++23 | 2.3kb | 2023-10-08 17:56:03 | 2023-10-08 17:56:04 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;
int n,m,a[N],b[N],c[N],sum,s[N][5];
bool check(ll x) { //x=ksum+b
ll k=x/n,yu=x%n;
ll s1=k*s[n][1]+s[yu][1],s2=k*s[n][2]+s[yu][2],s3=k*s[n][3]+s[yu][3];
for(int i=1;i<=m;++i) {
c[i]=b[i];
if(s3&&(b[i]&1)&&(b[i]>1)) b[i]-=3,s3--;
}
/* printf("%d %d %d\n",s1,s2,s3);
for(int i=1;i<=m;++i) {
printf("%d ",b[i]);
}
puts("");*/
if(s3) {
for(int i=1;i<=m;++i) {
if((b[i]/6)*2<=s3) {
s3-=(b[i]/6)*2;
b[i]%=6;
} else {
if(b[i]/3>=s3) {
b[i]-=3*s3;
} else {
b[i]-=6*(s3/2);
s3%=2;
}
break;
}
}
}
/* printf("%d %d %d\n",s1,s2,s3);
for(int i=1;i<=m;++i) {
printf("%d ",b[i]);
}
puts("");*/
if(s3) {
for(int i=1;i<=m;++i) {
if(b[i]>3) {
b[i]-=3;
s3--;
if(s3==0) break;
}
}
}
s2+=s3; s3=0;
/* printf("%d %d %d\n",s1,s2,s3);
for(int i=1;i<=m;++i) {
printf("%d ",b[i]);
}
puts("");*/
/* if(s3) {
for(int i=1;i<=m;++i) {
if(b[i]==2) {
s3--;
b[i]=0;
if(s3==0) break;
}
}
}
if(s3) {
for(int i=1;i<=m;++i) {
if(b[i]==1) {
s3--;
b[i]=0;
if(s3==0) break;
}
}
}*/
/* printf("%d %d %d\n",s1,s2,s3);
for(int i=1;i<=m;++i) {
printf("%d ",b[i]);
}
puts("");*/
if(s2) {
for(int i=1;i<=m;++i) {
if(b[i]/2<=s2) {
s2-=b[i]/2;
b[i]%=2;
if(s2==0) break;
} else {
b[i]-=s2*2;
s2=0;
break;
}
}
}
if(s2) {
for(int i=1;i<=m;++i) {
if(b[i]&&s2) {
s2--; b[i]=0;
if(s2==0) break;
}
}
}
for(int i=1;i<=m;++i ){
if(b[i]>0) s1-=b[i],b[i]=0;
}
for(int i=1;i<=m;++i) b[i]=c[i];
return s1>=0;
}
int main() {
// freopen("1.in","r",stdin);
int T; scanf("%d",&T);
while(T--) {
scanf("%d",&n);
for(int i=1;i<=n;++i) {
scanf("%d",&a[i]);
for(int j=1;j<=3;++j) {
s[i][j]=s[i-1][j]+(a[i]==j);
}
}
scanf("%d",&m);
ll l=0,r=0;
for(int i=1;i<=m;++i) {
scanf("%d",&b[i]); r+=b[i];
}
sum=s[n][1]+2*s[n][2]+3*s[n][3];
l=r/sum*n; ll ans=0;
// printf("%d\n",check(4));
// printf("%lld %lld\n",l,r);
while(l<=r) {
ll mid=l+r>>1;
if(check(mid)) {
ans=mid,r=mid-1;
} else l=mid+1;
}
printf("%lld\n",ans);
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3948kb
input:
2 2 3 2 3 2 4 2 5 1 2 3 2 1 2 3 3
output:
4 3
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 5996kb
input:
100 21 1 3 3 3 2 3 3 2 2 1 3 2 1 3 2 1 1 1 3 3 3 3 3 3 1 19 1 3 1 1 3 3 1 3 2 3 2 2 3 3 1 1 2 2 2 10 2 2 3 1 5 2 2 5 5 3 8 1 3 3 1 3 2 3 1 3 1 2 1 27 1 1 1 2 1 3 1 2 2 3 3 3 1 1 1 1 2 1 2 2 2 2 3 2 1 3 2 4 5 1 2 2 23 2 1 3 2 3 2 2 3 1 2 1 3 1 2 3 1 3 1 2 2 2 1 1 10 4 3 5 4 5 4 1 4 3 4 8 1 2 1 3 2 3 ...
output:
3 15 3 7 19 12 3 8 7 20 5 10 6 10 3 10 16 1 5 6 10 14 13 8 8 5 13 15 5 10 16 14 10 1 10 4 3 16 5 4 7 8 7 5 13 10 10 10 14 3 9 8 19 16 8 25 11 21 2 3 14 12 4 12 17 22 11 3 14 15 2 9 12 7 3 9 4 9 11 2 2 5 5 3 2 2 4 6 7 10 3 14 2 1 5 4 8 13 14 16
result:
ok 100 lines
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3948kb
input:
100 22 3 3 3 1 3 2 3 3 3 3 2 2 3 3 1 2 1 2 3 2 3 1 3 10 1 8 11 1 3 2 1 3 3 1 1 1 1 1 3 3 5 13 21 3 1 2 3 2 1 2 1 3 2 2 1 1 1 1 3 2 3 2 3 2 4 1 5 7 10 8 2 1 3 3 2 2 2 2 3 8 11 8 4 2 1 1 2 2 12 8 26 1 2 3 3 1 2 2 2 2 1 3 1 3 2 1 2 1 3 2 1 1 3 2 3 3 2 4 8 6 5 13 30 1 1 3 2 2 1 2 3 1 3 3 2 3 2 2 3 1 2 3...
output:
8 13 10 12 13 17 11 7 6 20 3 5 10 19 2 22 9 10 3 4 17 12 10 3 8 3 9 17 1 20 8 26 6 11 12 10 12 9 17 5 4 11 17 17 18 16 4 16 8 2 13 20 8 8 15 14 15 11 20 19 7 24 5 13 7 5 4 16 1 4 7 9 10 13 7 11 10 2 5 3 3 16 26 8 8 8 10 2 8 4 7 7 18 2 9 22 15 20 14 12
result:
wrong answer 3rd lines differ - expected: '12', found: '10'