QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#36055#2571. Aidana and Pitaconqueror_of_zky#WA 233ms79656kbC++142.4kb2022-06-23 17:55:092022-06-23 17:55:12

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-23 17:55:12]
  • 评测
  • 测评结果:WA
  • 用时:233ms
  • 内存:79656kb
  • [2022-06-23 17:55:09]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
struct node
{
	int x,y,z;
	long long id;
};
inline bool cmp(node x,node y)
{
	return x.y-x.x<y.y-y.x;
}
int mn=1e9;
long long S=0;
vector <node> v1,v2;
int B,a[30];
inline void dfs1(int now,int x,int y,long long S)
{
	if(now==B+1)
	{
		v1.push_back({0,x,y,S});
		return ;
	}
	dfs1(now+1,x-a[now],y-a[now],S|(1ll<<now*2));
	dfs1(now+1,x+a[now],y,S|(2ll<<now*2));
	dfs1(now+1,x,y+a[now],S|(3ll<<now*2));
}
inline void dfs2(int now,int x,int y,int S)
{
	if(now==B)
	{
		v2.push_back({0,x,y,S});
		return ;
	}
	dfs2(now-1,x-a[now],y-a[now],S|(1ll<<now*2));
	dfs2(now-1,x+a[now],y,S|(2ll<<now*2));
	dfs2(now-1,x,y+a[now],S|(3ll<<now*2));
}
const int inf=1e9;
int W[2000005];
inline void solve()
{
	set <pair<int,pair<int,long long> > > s;
	sort(v1.begin(),v1.end(),cmp);
	sort(v2.begin(),v2.end(),cmp);
	for(int i=0;i<v2.size();i++)
		W[i]=v2[i].z-v2[i].x;
	s.insert({-inf,{-inf,0}});
	s.insert({inf,{-inf,0}});
	int now=v2.size()-1;
	for(auto t:v1)
	{
		int k=t.y-t.x;
	//	cout << t.y << "qwqwqwqwq" << t.z << "\n";
//		cout << k << "*\n";
		while(now>=0&&v2[now].y-v2[now].x+k>=0)
		{
			auto it=s.lower_bound({v2[now].y-v2[now].z,{W[now],0}});
			while((*it).second.first>W[now])
			{
				s.erase(it);
				it=s.lower_bound({v2[now].y-v2[now].z,{W[now],0}});
			}
			int flag=0;
			--it;
			if(it!=s.begin())
			{
				if(W[now]>(*it).second.first) flag=1;
			}
			if(!flag) s.insert({v2[now].y-v2[now].z,{W[now],v2[now].id}});
		//	cout << "!!!!!!!!!!!!!" << v2[now].y << " " << v2[now].z << "!!!!!!!!!!!!\n";
			--now;
		}
		pair<int,int> p=(*--s.lower_bound({t.z-t.y,{inf,0}})).second;
		if(t.z==-1&&t.x==1)
		{
//			cout << p.first << "   qwq                                          " << p.second << "\n";
		}
		if(p.first==-inf) continue;
		if(t.z-t.x+p.first<mn)
		{
			mn=t.z-t.x+p.first,S=t.id|p.second;
		//	cout << t.x << " " << t.y << " " << t.z << " " << t.id << "**\n";
		//	cout << v2[p].x << " " << v2[p].y << " " << v2[p].z << " " << v2[p].id << "**\n";
		}
	}
}
signed main()
{
	int n;
	cin >> n;
	B=(n+1)/2;
	for(int i=1;i<=n;i++)
		cin >> a[i];
	dfs1(1,0,0,0);
	dfs2(n,0,0,0);
/*	for(auto t:v1)
	{
		cout << t.y << " " << t.z << "\n";
	}
	cout << "\n\n";
	for(auto t:v2)
	{
		cout << t.y << " " << t.z << "\n";
	}*/
	solve(); 
	for(int i=1;i<=n;i++)
	{
		cout << (S>>i*2)%4 << " ";
	}
	return 0;
}
/*
3
3 2 1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3708kb

input:

5
2 3 1 4 2

output:

3 1 1 2 3 

result:

ok answer is 0

Test #2:

score: 0
Accepted
time: 0ms
memory: 3624kb

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: 2ms
memory: 3696kb

input:

3
2617460 3290620 1468912

output:

2 3 1 

result:

ok answer is 1821708

Test #4:

score: -100
Wrong Answer
time: 233ms
memory: 79656kb

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 -3 -3 -1 -3 -3 -1 -3 -1 -1 -1 -3 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 

result:

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