QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#20543 | #2571. Aidana and Pita | Appleblue17# | RE | 278ms | 535208kb | C++14 | 2.0kb | 2022-02-16 15:26:22 | 2022-05-03 10:27:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e7+5,B=1e7,INF=1e9;
#define $ +B
int n,a[N];
long long pw[N];
struct abc{
int x,y;
long long pos;
int val;
abc(int X=0,int Y=0,long long Z=0,int W=INF){
x=X,y=Y,pos=Z,val=W;
}
};
bool operator <(abc X,abc Y){
return X.x<Y.x;
}
void getmin(abc &X,abc Y){
if(Y.val<X.val) X=Y;
}
vector <abc> P,Q;
void dfs1(int dep,int ed,int x,int y,int z,long long s){
if(dep>ed){
P.push_back((abc){y-x,z-y,s,z-x});
// cout<<"P: "<<y-x<<" "<<z-y<<" "<<z-x<<endl;
return ;
}
dfs1(dep+1,ed,x+a[dep],y,z,s);
dfs1(dep+1,ed,x,y+a[dep],z,s+pw[dep]);
dfs1(dep+1,ed,x,y,z+a[dep],s+2*pw[dep]);
}
void dfs2(int dep,int ed,int x,int y,int z,long long s){
if(dep>ed){
Q.push_back((abc){x-y,y-z,s,z-x});
// cout<<"Q: "<<x-y<<" "<<y-z<<" "<<z-x<<endl;
return ;
}
dfs2(dep+1,ed,x+a[dep],y,z,s);
dfs2(dep+1,ed,x,y+a[dep],z,s+pw[dep]);
dfs2(dep+1,ed,x,y,z+a[dep],s+2*pw[dep]);
}
abc c[N];
int lowbit(int x){
return x & (-x);
}
void modify(int x,abc k){
while(x<N) getmin(c[x],k),x+=lowbit(x);
}
abc query(int x){
abc tot;
while(x) getmin(tot,c[x]),x-=lowbit(x);
return tot;
}
int main(){
pw[0]=1;
for(int i=1;i<=30;i++) pw[i]=pw[i-1]*3;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
int m=n/2;
dfs1(1,m,0,0,0,0);
dfs2(m+1,n,0,0,0,0);
sort(P.begin(),P.end());
sort(Q.begin(),Q.end());
abc ans;
int p=-1;
for(int i=0;i<(int)P.size();i++){
while(p+1<Q.size() && Q[p+1].x<=P[i].x) p++,modify(Q[p].y $,Q[p]);
abc tot=query(P[i].y $);
getmin(ans,(abc){0,0,P[i].pos+tot.pos,P[i].val+tot.val});
}
// for(int x=-B;x<=B;x++){
// for(int y=-B;y<=x;y++){
// for(int i=0;i<(int)P[x $].size();i++){
// for(int j=0;j<(int)Q[y $].size();j++){
// if(P[x $][i].x>=Q[y $][j].x)
// getmin(ans,(abc){0,P[x $][i].pos+Q[y $][j].pos,P[x $][i].val+Q[y $][j].val});
// }
// }
// }
// }
for(int i=1;i<=n;i++) cout<<ans.pos/pw[i]%3+1<<" ";
}
詳細信息
Test #1:
score: 100
Accepted
time: 56ms
memory: 473080kb
input:
5 2 3 1 4 2
output:
3 1 1 2 3
result:
ok answer is 0
Test #2:
score: 0
Accepted
time: 60ms
memory: 472560kb
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: 77ms
memory: 473436kb
input:
3 2617460 3290620 1468912
output:
2 3 1
result:
ok answer is 1821708
Test #4:
score: 0
Accepted
time: 254ms
memory: 534252kb
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 1 3 1 3 1 3 1 3 1 1 3 3 2 3 3 3 2 2 2 2 2 2 2 3
result:
ok answer is 0
Test #5:
score: 0
Accepted
time: 278ms
memory: 535208kb
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 1 3 1 1 1 3 1 3 1 3 1 2 3 2 2 2 3 2 3 2 3 2 3 3
result:
ok answer is 1
Test #6:
score: -100
Runtime Error
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