QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#630158 | #6769. Monster Hunter | moyujiang | WA | 1ms | 3856kb | C++14 | 1.7kb | 2024-10-11 16:47:25 | 2024-10-11 16:47:27 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a),i##END=(b);i<=i##END;i++)
#define Rof(i,b,a) for(int i=(b),i##END=(a);i>=i##END;i--)
#define go(u) for(int i=head[u];i;i=nxt[i])
#define int long long
using namespace std;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
return x*f;
}
const int N=1e5+10;
int n,m,a[N],h[N],b[N];
bool check(int K){
// printf("K = %lld\n",K);
For(i,1,m)h[i]=b[i];
int o[4];
o[3]=o[1]=o[2]=0;
For(i,1,n)o[a[i]]+=(K/n);
For(i,1,K%n)o[a[i]]++;
For(i,1,m){
if(h[i]==1){
int fl=0;
For(v,1,3)if(o[v]){o[v]--,h[i]=0;fl=1;break;}
if(!fl)return 0;
continue;
}
if(h[i]%2){
if(o[3])o[3]--,h[i]-=3;
else if(o[1])o[1]--,h[i]--;
else h[i]++;
}
}
// For(i,1,m)printf("%lld ",h[i]);puts("");
For(i,1,m){
int c=min({o[1],o[3],h[i]/4});
o[1]-=c,o[3]-=c,h[i]-=4*c;
int x=h[i]/6;
c=min(o[3]/2,x);
x-=c,o[3]-=2*c;
x=h[i]/2;
h[i]-=c*6;
c=min(x,o[2]);
h[i]-=c*2,o[2]-=c;
if(h[i]>=3&&o[3])o[3]--,h[i]-=3;
if(h[i]&&h[i]<=2&&!o[1]&&o[3])o[3]--,h[i]=0;
if(h[i]>o[1]){
return 0;
}
o[1]-=h[i];
}
return 1;
}
signed main(){
int T=read();while(T--){
For(i,1,n=read())a[i]=read();
For(i,1,m=read())h[i]=b[i]=read();
// cout<<check(3)<<endl;
// return 0;
// For(i,1,10)printf("check(%lld) = %lld\n",i,check(i));
// For(i,1,10)printf("check(%lld) = %lld\n",i,check(i));
int l=1,r=1e16;while(l<=r){
int mid=l+r>>1;
if(check(mid))r=mid-1;
else l=mid+1;
// printf("[%lld, %lld]\n",l,r);
}printf("%lld\n",r+1);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3784kb
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: -100
Wrong Answer
time: 1ms
memory: 3856kb
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 18 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 4 16 5 4 7 8 7 5 13 11 10 38 15 3 10 8 19 16 8 25 11 21 2 3 15 12 4 12 17 22 11 3 14 15 2 9 12 7 3 9 4 9 11 2 2 5 5 4 2 2 4 6 7 10 3 14 2 1 5 4 10 13 14 16
result:
wrong answer 2nd lines differ - expected: '15', found: '18'