QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#152217 | #2571. Aidana and Pita | zyxawa | WA | 248ms | 153268kb | C++23 | 1.5kb | 2023-08-27 19:13:30 | 2023-08-27 19:13:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
ll c1,c2,a,b,c,f;
node(ll k1=0,ll k2=0,ll k3=0,ll k4=0,ll k5=0,ll k6=0){c1=k1,c2=k2,a=k3,b=k4,c=k5,f=k6;}
bool operator<(const node &k)const{
if(c1!=k.c1) return c1<k.c1;
else return c2<k.c2;
}
}a1[1594324],a2[1594324];
int n,t1,t2,id,len,a[26],w[26];
ll ans1,ans2,ans=1e16,sum;
void dfs1(int pos,ll sa,ll sb,ll sc,ll s){
if(pos==(n+1)/2+1){
a1[++t1]=node(sa-sb,sc,sa,sb,sc,s);
return;
}
dfs1(pos+1,sa+a[pos],sb,sc,s*3);
dfs1(pos+1,sa,sb+a[pos],sc,s*3+1);
dfs1(pos+1,sa,sb,sc+a[pos],s*3+2);
}
void dfs2(int pos,ll sa,ll sb,ll sc,ll s){
if(pos==n+1){
a2[++t2]=node(sa-sb,sc,sa,sb,sc,s);
return;
}
dfs2(pos+1,sa+a[pos],sb,sc,s*3);
dfs2(pos+1,sa,sb+a[pos],sc,s*3+1);
dfs2(pos+1,sa,sb,sc+a[pos],s*3+2);
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]),sum+=a[i];
sum/=3ll;
dfs1(1,0,0,0,0);
dfs2((n+1)/2+1,0,0,0,0);
sort(a1+1,a1+1+t1);
for(int i=1;i<=t2;i++){
id=lower_bound(a1+1,a1+1+t1,node(a2[i].b-a2[i].a,sum-a2[i].c))-a1;
for(int j=max(1,id-10);j<=min(t1,id+10);j++){
ll sa=a1[j].a+a2[i].a,sb=a1[j].b+a2[i].b,sc=a1[j].c+a2[i].c;
if(max({sa,sb,sc})-min({sa,sb,sc})<ans) ans=max({sa,sb,sc})-min({sa,sb,sc}),ans1=a1[j].f,ans2=a2[i].f;
}
}
for(int i=1;i<=(n+1)/2;i++) w[++len]=ans1%3+1,ans1/=3;
for(int i=len;i>=1;i--) printf("%d ",w[i]);
len=0;
for(int i=(n+1)/2+1;i<=n;i++) w[++len]=ans2%3+1,ans2/=3;
for(int i=len;i>=1;i--) printf("%d ",w[i]);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 16ms
memory: 153112kb
input:
5 2 3 1 4 2
output:
2 3 3 1 2
result:
ok answer is 0
Test #2:
score: 0
Accepted
time: 4ms
memory: 153076kb
input:
6 3 2 5 3 4 2
output:
1 3 3 1 2 2
result:
ok answer is 1
Test #3:
score: 0
Accepted
time: 4ms
memory: 153080kb
input:
3 2617460 3290620 1468912
output:
3 2 1
result:
ok answer is 1821708
Test #4:
score: 0
Accepted
time: 242ms
memory: 153084kb
input:
25 6 6 7 8 5 10 5 7 10 10 4 4 5 8 1 6 3 1 9 4 10 7 8 4 5
output:
3 3 3 2 3 2 3 3 3 2 2 2 3 1 1 1 1 1 1 1 1 2 2 1 1
result:
ok answer is 0
Test #5:
score: 0
Accepted
time: 186ms
memory: 153268kb
input:
25 8 2 2 9 9 10 3 5 9 1 2 5 8 1 4 8 4 3 6 2 8 8 4 2 2
output:
3 2 2 2 2 3 3 3 2 2 3 3 3 1 1 1 1 1 1 1 1 2 1 1 2
result:
ok answer is 1
Test #6:
score: -100
Wrong Answer
time: 248ms
memory: 153116kb
input:
25 9999996 9999999 9999991 9999991 9999999 9999997 9999991 9999993 9999992 10000000 9999991 10000000 9999996 9999997 9999993 9999992 9999990 9999991 9999997 10000000 9999998 9999990 9999993 9999990 9999999
output:
2 2 3 3 2 1 3 3 2 1 3 2 2 1 1 1 3 3 1 1 1 3 2 3 2
result:
wrong answer expected 9999943, found 9999944