QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#115178 | #5851. Travel Plan | zhouhuanyi | 3 | 1ms | 3596kb | C++11 | 1.5kb | 2023-06-24 20:14:14 | 2023-06-24 20:14:16 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#define N 15
using namespace std;
long long read()
{
char c=0;
long long sum=0,f=1;
while (c!='-'&&(c<'0'||c>'9')) c=getchar();
if (c=='-') c=getchar(),f=-1;
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum*f;
}
int T,n,Base;
const long long inf=(long long)(1e18);
long long a[N+1],F,ans;
vector<long long>p[N+1];
vector<long long>q[N+1];
void dfs(int x,int d,long long res)
{
if (x==Base+1)
{
p[d].push_back(res);
return;
}
if (x==1||d) dfs(x+1,d+1,res-(a[x]<<1));
if (d) dfs(x+1,d,res),dfs(x+1,d-1,res+(a[x]<<1));
return;
}
void dfs2(int x,int d,long long res)
{
if (x==Base)
{
q[d].push_back(res);
return;
}
if (x==n||d) dfs2(x-1,d+1,res+(a[x]<<1));
if (d) dfs2(x-1,d,res),dfs2(x-1,d-1,res-(a[x]<<1));
return;
}
int main()
{
int ps;
T=read();
for (int qt=1;qt<=T;++qt)
{
n=read(),Base=n>>1,ans=-inf;
for (int i=1;i<=n;++i) a[i]=read();
F=read(),sort(a+1,a+n+1);
for (int i=0;i<=Base;++i) p[i].clear(),q[i].clear();
dfs(1,0,0),dfs2(n,0,0);
for (int i=1;i<=Base;++i)
{
sort(p[i].begin(),p[i].end()),sort(q[i].begin(),q[i].end()),ps=-1;
for (int j=(int)(q[i].size())-1;j>=0;--j)
{
while (ps+1<p[i].size()&&p[i][ps+1]+q[i][j]<=F) ++ps;
if (ps!=-1) ans=max(ans,p[i][ps]+q[i][j]);
}
}
if (ans==-inf) printf("Case #%d: NO SOLUTION\n",qt);
else printf("Case #%d: %lld\n",qt,ans);
}
return 0;
}
详细
Subtask #1:
score: 3
Accepted
Test #1:
score: 3
Accepted
time: 1ms
memory: 3596kb
input:
100 3 0 10 -10 40 5 0 1 2 3 4 13 5 0 1 2 3 4 7 8 0 789059689301482 -910931693858101 -956193093955857 343509202930243 920374185149989 -689955229424826 722030552663468 482269012678218 7 0 999999999999544 999999999999389 999999999999930 -999999999999063 -999999999999192 -999999999999596 417587359369470...
output:
Case #1: 40 Case #2: 12 Case #3: NO SOLUTION Case #4: NO SOLUTION Case #5: 3999999999999620 Case #6: 4051752 Case #7: NO SOLUTION Case #8: NO SOLUTION Case #9: 1999999999998958 Case #10: 7010924229270316 Case #11: 4595167479146090 Case #12: 3500897892661482 Case #13: NO SOLUTION Case #14: NO SOLUTIO...
result:
ok 100 lines
Subtask #2:
score: 0
Runtime Error
Test #2:
score: 0
Runtime Error
input:
20 28 0 -296203321911394 -669869184126344 878407950821263 -835889965067355 421301173991167 -801344314893054 403607682072382 227003460040564 154808607155152 767043420856216 -346030550495039 -992039850227156 -785288091280455 -466542633673897 -216447853885253 -183726687442679 443056439241543 6555553252...