QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#20542#2571. Aidana and PitaAppleblue17#WA 84ms472748kbC++142.0kb2022-02-16 15:26:002022-05-03 10:27:47

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-03 10:27:47]
  • 评测
  • 测评结果:WA
  • 用时:84ms
  • 内存:472748kb
  • [2022-02-16 15:26:00]
  • 提交

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});
//				}
//			}
//		}
//	}
	
	cout<<ans.val<<endl;
	for(int i=1;i<=n;i++) cout<<ans.pos/pw[i]%3+1<<" ";
}

详细

Test #1:

score: 0
Wrong Answer
time: 84ms
memory: 472748kb

input:

5
2 3 1 4 2

output:

0
3 1 1 2 3 

result:

wrong answer all numbers must be in [1, 2, 3], found= c[1]=0