QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#128412 | #6667. Prosjek | DerekFeng | 0 | 219ms | 14396kb | C++23 | 3.1kb | 2023-07-20 22:44:14 | 2023-07-20 22:44:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+4;
int n;vector<ll>a[4];
vector<pair<ll,ll> >ans;
void upd(int s,int t){
ll x=a[s].back();a[s].pop_back();
ll y=a[t].back();a[t].pop_back();
ans.emplace_back(x,y);
x=x+y>>1,a[x&3].emplace_back(x);
}
void sub(int s){
int t=s+2;
while(a[s].size()>1||a[t].size()>1){
while(a[s].size()>1)upd(s,s);
while(a[t].size()>1)upd(t,t);
}
if(!a[s].empty()&&!a[t].empty())ans.emplace_back(s,t);
for(auto&[x,y]:ans)cout<<x<<' '<<y<<'\n';
}
bool check(int s){
if(!a[s].empty()&&!a[s+2].empty())return 1;
if(a[s].empty())s+=2;
for(int i=1;i<a[s].size();i++){
ll x=a[s][i]^a[s][i-1];
if(x&&__builtin_ctz(x)<a[s].size())return 1;
}
return 0;
}
void calc(int s){
if(!a[s].empty()&&!a[s+2].empty())return;
if(a[s].empty())s+=2;
int ret=100,pos;
for(int i=1;i<a[s].size();i++){
ll x=a[s][i]^a[s][i-1];
if(x&&__builtin_ctz(x)<ret)ret=__builtin_ctz(x),pos=i;
}
ans.emplace_back(a[s][pos-1],a[s][pos]);
ll A=a[s][pos-1]+a[s][pos]>>1;
a[s].erase(a[s].begin()+pos-1),a[s].erase(a[s].begin()+pos-1),a[A&3].emplace_back(A);
for(int i=ret-1;i>1;i--)upd(s,s);
}
void sol(int s){
int t=s+2;
ll x=a[s].back(),y=a[t].back();a[s].pop_back(),a[t].pop_back();
while(a[0].size()+a[2].size()>1||a[1].size()+a[3].size()>1){
while(a[0].size()>1)upd(0,0);
while(a[1].size()>1)upd(1,1);
while(a[2].size()>1)upd(2,2);
while(a[3].size()>1)upd(3,3);
while(!a[0].empty()&&!a[2].empty())upd(0,2);
while(!a[1].empty()&&!a[3].empty())upd(1,3);
}
if(a[0].size()+a[2].size()>0&&a[1].size()+a[3].size()>0){
ll S=s,T=s^1;if(a[S].empty())S^=2;if(a[T].empty())T^=2;
S=a[S][0],T=a[T][0];vector<ll>vec;
if(~((x>>2)^(S>>2))&1)ans.emplace_back(x,S),vec={x+S>>1,y,T};
else if(~((y>>2)^(S>>2))&1)ans.emplace_back(y,S),vec={y+S>>1,x,T};
else ans.emplace_back(x,y),vec={x+y>>1,S,T};
if((vec[0]&1)==(vec[1]&1))ans.emplace_back(vec[0],vec[1]),ans.emplace_back(vec[0]+vec[1]>>1,vec[2]);
else if((vec[0]&1)==(vec[2]&1))ans.emplace_back(vec[0],vec[2]),ans.emplace_back(vec[0]+vec[2]>>1,vec[1]);
else ans.emplace_back(vec[1],vec[2]),ans.emplace_back(vec[1]+vec[2]>>1,vec[0]);
}else{
if(a[s].size()+a[t].size()>0){
if(!a[s].empty()){
ans.emplace_back(x,a[s][0]),x=x+a[s][0]>>1;
ans.emplace_back(x,y);
}else{
ans.emplace_back(y,a[t][0]),y=y+a[t][0]>>1;
ans.emplace_back(x,y);
}
}else if(a[s^1].size()+a[t^1].size()>0){
ans.emplace_back(x,y),x=x+y>>1;
if(!a[s^1].empty())ans.emplace_back(x,a[s^1][0]);
if(!a[t^1].empty())ans.emplace_back(x,a[t^1][0]);
}else ans.emplace_back(x,y);
}
for(auto&[x,y]:ans)cout<<x<<' '<<y<<'\n';
}
void sol(){
cin>>n,a[0].clear(),a[1].clear(),a[2].clear(),a[3].clear(),ans.clear();
for(int i=0;i<n;i++){ll x;cin>>x;a[x&3].emplace_back(x);}
if(a[1].empty()&&a[3].empty()){sub(0);return;}
if(a[0].empty()&&a[2].empty()){sub(1);return;}
if(check(0)){calc(0),sol(0);return;}
if(check(1)){calc(1),sol(1);return;}
cout<<-1<<'\n';
}
int main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
int tc;cin>>tc;while(tc--)sol();
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3568kb
input:
99 4 739880851158065302 19206582949872932 883064254701115295 222072661880779376 7 148399819461615003 209088712310207988 53191076581680214 445068618251612752 230505279594622109 115754892157516718 804173775829453588 2 77979357045500669 41693388829622019 3 341612949433488278 609808714829036935 19994167...
output:
739880851158065302 19206582949872932 379543717053969117 883064254701115295 631303985877542206 222072661880779376 445068618251612752 209088712310207988 327078665280910370 53191076581680214 230505279594622109 148399819461615003 189452549528118556 190134870931295292 804173775829453588 18979371022970692...
result:
wrong answer there's no 1 in the current set (test case 3)
Subtask #2:
score: 0
Wrong Answer
Test #16:
score: 0
Wrong Answer
time: 0ms
memory: 3448kb
input:
100 3 3 3 2 3 4 1 1 4 1 3 4 4 6 4 4 2 3 1 2 4 0 2 1 4 3 0 2 0 7 3 3 1 1 3 4 0 2 0 4 4 1 4 2 3 7 4 0 0 3 2 3 4 4 4 2 0 3 7 0 2 2 1 4 2 4 7 3 0 3 1 2 0 3 4 4 3 1 4 6 2 3 0 1 3 4 5 1 4 0 3 4 5 4 2 0 4 2 3 0 1 2 6 4 1 4 2 0 4 7 4 2 4 3 1 3 1 4 1 4 4 0 2 1 1 6 0 3 3 0 0 4 7 4 3 0 3 3 3 4 4 4 1 1 3 6 2 0 ...
output:
-1 -1 4 4 1 3 2 4 4 2 1 3 2 2 2 4 3 3 2 0 1 1 1 4 0 0 0 2 0 4 3 3 1 3 2 2 1 3 2 2 4 0 1 3 2 2 4 2 0 0 0 4 3 3 2 2 2 4 3 3 0 2 1 3 2 4 4 0 2 2 2 2 2 2 2 4 3 1 3 3 3 3 1 3 0 2 0 2 1 1 4 4 1 3 2 4 3 3 1 3 0 2 4 2 3 1 4 0 1 3 2 2 4 2 4 0 2 2 2 2 0 2 0 2 1 1 0 4 4 2 1 3 2 2 4 2 1 1 3 3 1 3 4 2 4 2 3 3 4 ...
result:
wrong answer (1 + 4) is not an even number! (test case 5)
Subtask #3:
score: 0
Wrong Answer
Test #34:
score: 0
Wrong Answer
time: 109ms
memory: 3460kb
input:
100000 5 846784256447769304 457696478728961702 128469521648960690 597630796847754190 104256763714529164 5 658897822238868978 472135077337628566 399538027669313322 622703684108675696 425723088635325654 5 917704960887390986 140817562615382054 877934664521057998 782212806618666818 616380973421914538 8 ...
output:
104256763714529164 846784256447769304 475520510081149234 597630796847754190 128469521648960690 457696478728961702 293083000188961196 536575653464451712 425723088635325654 399538027669313322 472135077337628566 658897822238868978 565516449788248772 412630558152319488 0 2 616380973421914538 78221280661...
result:
wrong answer there's no 0 in the current set (test case 2)
Subtask #4:
score: 0
Wrong Answer
Test #46:
score: 0
Wrong Answer
time: 219ms
memory: 14396kb
input:
100 211957 911918942087402387 344230223346742784 16289402153237664 528890583619159010 886281719684850237 865484734102017297 321851390502278959 754268375474197153 237414161302130571 135637002716682378 824412491959977735 162505521049217610 246319278060116103 666703181591704279 650875500699154233 96397...
output:
897655518245439560 780438536468326472 839047027356883016 444950768839720960 641998898098301988 186730312418961600 988268985652269236 473341823171477140 730805404411873188 109948005973364296 494927481562234444 365104786688751580 430016134125493012 224603118414672644 327309626270082828 908275570361964...
result:
wrong answer (447679429435012981 + 565571528123858342) is not an even number! (test case 3)