QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#30279 | #2571. Aidana and Pita | yzhang | TL | 1797ms | 96704kb | C++17 | 3.6kb | 2022-04-26 18:06:48 | 2022-04-28 16:46:28 |
Judging History
answer
//μ's forever
#include <bits/stdc++.h>
#define N 1000005
//#define getchar nc
using namespace std;
inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int read()
{
register int x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return x*f;
}
inline void write(register int x)
{
if(!x)putchar('0');if(x<0)x=-x,putchar('-');
static int sta[20];register int tot=0;
while(x)sta[tot++]=x%10,x/=10;
while(tot)putchar(sta[--tot]+48);
}
int n;
int val[30];
int p[4];
struct node{
int x,y,tp,val,id;
}t[N*2];
bool cmp(node a,node b){
if(a.x==b.x) return a.tp>b.tp;
return a.x<b.x;
}
int tot;
struct tnode{
int ls,rs,val,id;
}tr[N*50];
int totn,rt;
void modify(int &x,int l,int r,int pos,int val,int id){
// if(pos!=0) cerr<<pos;
if(!x){
x=++totn;
tr[x].val=1145141919;
tr[x].ls=tr[x].rs=0;
}
if(val<tr[x].val) tr[x].val=val,tr[x].id=id;
if(l==r) return;
int mid=l+r>>1;
if(pos<=mid) modify(tr[x].ls,l,mid,pos,val,id);
else modify(tr[x].rs,mid+1,r,pos,val,id);
}
tnode qry(int x,int l,int r,int L,int R){
// if(x==rt) cerr<<L<<" "<<R<<endl;
if(!x) return (tnode){0,0,1145141919,0};
if(L<=l&&r<=R) return tr[x];
int mid=l+r>>1;
tnode res=(tnode){0,0,1145141919,0};
if(L<=mid){
res=qry(tr[x].ls,l,mid,L,R);
}
if(R>mid){
tnode tmp=qry(tr[x].rs,mid+1,r,L,R);
if(tmp.val<res.val) res=tmp;
}
return res;
}
int ans=1145141919,m1=0,m2=0;
int main()
{
n=read();
for(int i=1;i<=n;++i) val[i]=read();
for(int i=n+1;i<=25;++i) val[i]=0;
for(int i=1;i<=3;++i) p[i]=i;
do{
if(p[1]==1&&p[2]==3&&p[3]==2) continue;
if(p[1]==3&&p[2]==1&&p[3]==2) continue;
if(p[1]==3&&p[2]==2&&p[3]==1) continue;
tot=0;
for(int i=0;i<531441;++i){
int v[4],kk=i;
v[1]=val[1],v[2]=v[3]=0;
for(int j=2;j<=13;++j){
v[kk%3+1]+=val[j];
kk/=3;
}
// if(i==371564)cerr<<v[p[1]]-v[p[3]]<<endl;
t[++tot]=(node){v[p[1]]-v[p[2]],v[p[2]]-v[p[3]],1,v[p[1]]-v[p[3]],i};
// cerr<<t[tot].val<<endl;
}
for(int i=0;i<531441;++i){
int v[4],kk=i;
v[1]=v[2]=v[3]=0;
for(int j=14;j<=25;++j){
v[kk%3+1]+=val[j];
kk/=3;
}
t[++tot]=(node){v[p[2]]-v[p[1]],v[p[3]]-v[p[2]],2,v[p[1]]-v[p[3]],i};
}
sort(t+1,t+1+tot,cmp);
rt=totn=0;
for(int i=1;i<=tot;++i){
if(t[i].tp==1){
tnode tmp=qry(rt,-250000000,250000000,-250000000,t[i].y);
if(tmp.val!=1145141919){
if(t[i].val+tmp.val<ans){
// cerr<<t[i].id<<endl;
// cerr<<t[i].val<<" "<<tmp.val<<endl;
ans=t[i].val+tmp.val;
m1=t[i].id,m2=tmp.id;
}
}
}else{
modify(rt,-250000000,250000000,t[i].y,t[i].val,t[i].id);
}
}
}while(next_permutation(p+1,p+4));
// cerr<<ans<<endl;
printf("1 ");
for(int i=2;i<=min(n,13);++i){
printf("%d ",m1%3+1);
m1/=3;
}
for(int i=14;i<=min(n,25);++i){
printf("%d ",m2%3+1);
m2/=3;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 439ms
memory: 26232kb
input:
5 2 3 1 4 2
output:
1 3 3 2 1
result:
ok answer is 0
Test #2:
score: 0
Accepted
time: 443ms
memory: 28236kb
input:
6 3 2 5 3 4 2
output:
1 3 2 1 3 2
result:
ok answer is 1
Test #3:
score: 0
Accepted
time: 305ms
memory: 26312kb
input:
3 2617460 3290620 1468912
output:
1 2 3
result:
ok answer is 1821708
Test #4:
score: 0
Accepted
time: 799ms
memory: 26196kb
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:
1 3 2 2 2 3 2 2 2 3 3 2 2 1 1 1 3 1 1 1 3 1 3 1 1
result:
ok answer is 0
Test #5:
score: 0
Accepted
time: 768ms
memory: 26260kb
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:
1 3 3 2 2 3 3 3 2 3 2 2 2 3 1 3 3 3 1 1 1 1 1 3 1
result:
ok answer is 1
Test #6:
score: 0
Accepted
time: 790ms
memory: 26252kb
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:
1 1 2 2 1 3 2 1 1 1 2 1 1 3 3 2 2 2 3 3 3 2 3 2 3
result:
ok answer is 9999943
Test #7:
score: 0
Accepted
time: 680ms
memory: 26256kb
input:
25 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000 10000000
output:
1 3 2 3 2 2 2 3 2 3 2 2 2 3 3 1 1 1 1 1 3 1 3 1 1
result:
ok answer is 10000000
Test #8:
score: 0
Accepted
time: 1791ms
memory: 96436kb
input:
25 4568194 6252832 2990361 6179671 5525735 3402540 12193 4812907 2393092 9823299 4089880 1724585 2200631 5143163 5750864 5341161 5957736 2310544 8033121 9675751 9295231 71902 6463783 7667395 5613033
output:
1 3 3 3 3 3 2 2 2 1 1 3 3 2 3 1 1 1 2 1 2 3 2 3 2
result:
ok answer is 49
Test #9:
score: 0
Accepted
time: 1636ms
memory: 93280kb
input:
25 7762025 9149481 7523209 4813111 6800820 1960599 4807700 5411348 4528299 7599785 3468951 537831 6539799 2655771 1259341 9722159 506693 2973008 7910966 3611985 6228870 4141646 9112851 1735188 6538160
output:
1 2 3 1 2 1 1 3 1 1 3 3 1 1 1 2 1 2 2 3 3 2 3 2 3
result:
ok answer is 145
Test #10:
score: 0
Accepted
time: 1772ms
memory: 96704kb
input:
25 4732744 6239034 6860504 9029957 848680 209411 3629865 1309532 7860007 2831327 1707125 320774 4082248 4458046 8318819 7279399 861428 5020696 716989 8764261 952311 9612131 5994738 7283372 5509248
output:
1 1 1 2 1 1 1 3 3 1 3 3 3 2 2 3 2 3 2 2 3 3 2 1 1
result:
ok answer is 53
Test #11:
score: 0
Accepted
time: 1674ms
memory: 93088kb
input:
25 3926971 5832018 518527 8763702 973269 4552634 6533999 2808656 1277522 5063756 3389181 9876771 4222160 9001717 3592108 5852492 7874646 507942 8922016 4798000 1131210 9081684 512549 3399413 3253241
output:
1 3 3 2 1 3 1 3 3 2 3 2 3 1 1 3 1 3 2 2 2 3 3 1 1
result:
ok answer is 91
Test #12:
score: 0
Accepted
time: 1646ms
memory: 93196kb
input:
25 9383440 7906533 1692080 1331860 34750 3968473 2920448 8420499 271149 5986045 9894611 508079 1328124 2344042 9426700 8381332 7038317 4146561 5946221 3554163 215270 6084580 2549278 2162818 3791345
output:
1 2 1 3 3 3 3 1 3 2 1 2 3 3 3 2 1 2 2 2 3 3 3 3 3
result:
ok answer is 110
Test #13:
score: 0
Accepted
time: 1797ms
memory: 91540kb
input:
25 4046088 7315708 7288467 1966990 9827334 4635838 8767858 753173 7611802 8291513 4297560 3224050 8917952 5408746 3999749 761012 1332251 409871 2394270 1464938 7524338 2072107 3597866 4231339 9638829
output:
1 3 1 1 2 2 1 2 2 3 3 1 3 2 1 2 2 1 1 3 2 2 1 1 3
result:
ok answer is 101
Test #14:
score: -100
Time Limit Exceeded
input:
25 5547618 2099625 1573205 2912509 2335015 318412 5812834 9389294 7275632 2026666 7297673 3627332 1756646 7605338 5450938 6407663 678114 5237576 4788058 1293302 5458419 9269556 9795138 6180722 2919003