QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#564168 | #4207. Uplifting Excursion | hansiyuan | 0 | 2ms | 11832kb | C++14 | 1.8kb | 2024-09-14 21:00:33 | 2024-09-14 21:00:34 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1005;
int n,m,ans,res,x;
int neg[N],pos[N];
int f[N*N];
int nc[N],pc[N];
void solve(int v,int c,int w){
for(int t=1;c;t<<=1){
int x = min(c,t);
c-=x;
if(v>0){
for(int i=n*n*2;i>=1;i--)
f[i+v*x] = max(f[i]+w*x,f[i+v*x]);
}
else{
for(int i=v*x;i<=n*n*2;i++)
f[i+v*x] = max(f[i]+w*x,f[i+v*x]);
}
}
}
signed main(){
scanf("%lld%lld",&n,&m);
for(int i=n;i>=1;i--){
scanf("%lld",&neg[i]);
res -= neg[i]*i;
ans += neg[i];
nc[i] = neg[i];
}
int t;
scanf("%lld",&t);
ans += t;
for(int i=1;i<=n;i++){
scanf("%lld",&pos[i]);
res += pos[i]*i;
ans += pos[i];
pc[i] = pos[i];
}
if(res==m){
printf("%lld\n",ans);
return 0;
}
if(res<m){
int p=-1;
for(int i=n;i>=1;i--){
if(res+i*neg[i] >= m){p=i; break;}
res += i*neg[i];
ans -= neg[i];
nc[i]=0;
}
if(p==-1) {puts("impossible"); return 0;}
int l=0,r=neg[p];
while(l<r){
int mid = (l+r+1)>>1;
if(res+p*mid>=m) r=mid-1;
else l=mid;
}
ans -= l;
res += l*p;
nc[p] -= l;
}
else{
int p=-1;
for(int i=n;i>=1;i--){
if(res-i*pos[i]<=ans){p=i; break;}
res -= i*pos[i];
ans -= pos[i];
pc[i]=0;
}
if(p==-1) {puts("impossible"); return 0;}
int l=0,r=pos[p];
while(l<r){
int mid = (l+r+1)>>1;
if(res-p*mid<=ans) r=mid-1;
else l=mid;
}
ans -= l;
res -= l*p;
pc[p] -= l;
}
memset(f,-0x3f,sizeof(f));
f[n*n] = 0;
for(int i=1;i<=n;i++){
if(nc[i]) solve(i,nc[i],-1);
if(neg[i]-nc[i]) solve(-i,neg[i]-nc[i],1);
if(pc[i]) solve(-i,pc[i],-1);
if(pos[i]-pc[i]) solve(i,pos[i]-pc[i],1);
}
if(f[n*n+(m-res)]<-n*3) puts("impossible");
else printf("%d\n",ans+f[n*n+(m-res)]);
return 0;
}
详细
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 5
Accepted
time: 2ms
memory: 11832kb
input:
1 5 0 0 6
output:
5
result:
ok single line: '5'
Test #2:
score: 5
Accepted
time: 2ms
memory: 11816kb
input:
50 2303 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 3 5 25 50 0
output:
47
result:
ok single line: '47'
Test #3:
score: 0
Runtime Error
input:
50 -17964 18 21 8 47 11 30 0 34 11 22 10 29 14 39 25 42 16 47 6 39 0 4 28 5 4 39 43 47 14 49 24 37 22 47 23 31 18 28 43 14 44 26 46 40 27 17 41 7 13 25 27 20 17 13 23 30 9 16 5 25 46 22 35 44 34 39 19 19 33 11 30 30 41 20 1 9 39 34 31 26 28 13 13 21 45 11 32 30 35 37 22 31 1 9 43 18 31 41 34 39 2
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Runtime Error
Test #19:
score: 0
Runtime Error
input:
30 38887954194235 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 444113827766 26 511237030935 22 696666627923 315938808146 20 952560827478 924020644151 850666790939 23 587888300072 23 797812801251 911390834853 677171102320 4 2 22 950650764450 278888113729 23 15 15 13 9 637120041802 20 1...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #5:
0%
Subtask #8:
score: 0
Skipped
Dependency #6:
0%
Subtask #9:
score: 0
Skipped
Dependency #7:
0%
Subtask #10:
score: 0
Skipped
Dependency #1:
0%