QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#36054 | #2571. Aidana and Pita | conqueror_of_zky# | WA | 2ms | 3652kb | C++14 | 2.2kb | 2022-06-23 17:39:16 | 2022-06-23 17:39:17 |
Judging History
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;
while(now&&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}});
--now;
}
pair<int,int> p=(*--s.lower_bound({t.z-t.y,{inf,0}})).second;
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:v1)
{
cout << t.y << " " << t.z << "\n";
}
solve();
cerr << mn << "\n";*/
solve();
for(int i=1;i<=n;i++)
{
cout << (S>>i*2)%4 << " ";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3488kb
input:
5 2 3 1 4 2
output:
3 1 1 2 3
result:
ok answer is 0
Test #2:
score: 0
Accepted
time: 2ms
memory: 3652kb
input:
6 3 2 5 3 4 2
output:
1 3 3 1 2 2
result:
ok answer is 1
Test #3:
score: -100
Wrong Answer
time: 2ms
memory: 3524kb
input:
3 2617460 3290620 1468912
output:
3 2 3
result:
wrong answer expected 1821708, found 4086372