QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#117030 | #6667. Prosjek | xtqqwq# | 0 | 82ms | 11204kb | C++14 | 5.7kb | 2023-06-30 12:27:49 | 2024-05-31 18:37:52 |
Judging History
answer
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
ll readint(){
ll x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,cnt;
ll a[2000005];
bool vis[2000005];
vector<ll> b[20][10005];
vector<pll> c[4],ans;
pll merge(pll x,pll y){
ll res=(x.fi+y.fi)/2;
ans.pb(mp(x.fi,y.fi));
vis[x.se]=vis[y.se]=1;
a[++cnt]=res;
return mp(res,cnt);
}
void solve(){
ans.clear();
n=readint();
for(int i=1;i<=n+n;i++) vis[i]=0;
for(int i=0;i<4;i++) b[2][i].clear();
for(int i=0;i<4;i++) c[i].clear();
cnt=n;
for(int i=1;i<=n;i++) a[i]=readint();
for(int i=1;i<=n;i++) b[2][a[i]%4].pb(a[i]);
if(!b[2][0].size()&&!b[2][2].size()){
for(int i=1;i<n;i++){
if(b[2][1].size()>=2){
ll x=b[2][1].back(); b[2][1].pop_back();
ll y=b[2][1].back(); b[2][1].pop_back();
printf("%lld %lld\n",x,y);
b[2][(x+y)/2%4].pb((x+y)/2);
}
else if(b[2][3].size()>=2){
ll x=b[2][3].back(); b[2][3].pop_back();
ll y=b[2][3].back(); b[2][3].pop_back();
printf("%lld %lld\n",x,y);
b[2][(x+y)/2%4].pb((x+y)/2);
}
else printf("%lld %lld\n",b[2][1][0],b[2][3][0]);
}
return;
}
if(!b[2][0].size()||!b[2][2].size()){
int lst=b[2][0].size()?0:2;
vector<pll> vec;
for(int i=1;i<=n;i++) if(a[i]&1) vec.pb(mp(a[i],i));
for(int i=2;i<=60;i++){
vector<pll> tmp[2];
for(auto r:vec){
if(vis[r.se]) continue;
tmp[(r.fi>>(i-1))&1].pb(r);
}
if(tmp[0].size()&&tmp[1].size()){
if(i>2){
vec.pb(merge(tmp[0][0],tmp[1][0]));
i-=2;
}
else{
while(1){
if(tmp[0].size()>=2){
pll x1=tmp[0].back(); tmp[0].pop_back();
pll x2=tmp[0].back(); tmp[0].pop_back();
pll y=tmp[1].back(); tmp[1].pop_back();
if((x1.fi+y.fi)/2%4!=lst){
merge(x1,y);
break;
}
else if((x2.fi+y.fi)/2%4!=lst){
merge(x2,y);
break;
}
else{
tmp[1].pb(y);
tmp[0].pb(merge(x1,x2));
}
}
else if(tmp[1].size()>=2){
pll x1=tmp[1].back(); tmp[1].pop_back();
pll x2=tmp[1].back(); tmp[1].pop_back();
pll y=tmp[0].back(); tmp[0].pop_back();
if((x1.fi+y.fi)/2%4!=lst){
merge(x1,y);
break;
}
else if((x2.fi+y.fi)/2%4!=lst){
merge(x2,y);
break;
}
else{
tmp[0].pb(y);
tmp[1].pb(merge(x1,x2));
}
}
else{
merge(tmp[0][0],tmp[1][0]);
break;
}
}
break;
}
}
if(i==60) return (void)(printf("-1\n"));
}
}
// cout<<"test ";
// for(int i=1;i<=cnt;i++) if(!vis[i]) cout<<a[i]<<' ';
// cout<<endl;
int rt=0;
for(int i=1;i<=cnt;i++) if(!vis[i]&&a[i]%2==1) rt=i;
if(rt){
for(int i=1;i<=cnt;i++) if(!vis[i]&&a[i]%2==1) c[a[i]%4].pb(mp(a[i],i));
while(1){
if(c[1].size()+c[3].size()<=1) break;
if(c[1].size()>=2){
pll x=c[1].back(); c[1].pop_back();
pll y=c[1].back(); c[1].pop_back();
c[(x.fi+y.fi)/2%4].pb(merge(x,y));
}
else if(b[2][3].size()>=2){
pll x=c[3].back(); c[3].pop_back();
pll y=c[3].back(); c[3].pop_back();
c[(x.fi+y.fi)/2%4].pb(merge(x,y));
}
else{
merge(c[1][0],c[3][0]);
break;
}
}
}
rt=0;
for(int i=1;i<=cnt;i++) if(!vis[i]&&a[i]%2==1) rt=i;
if(rt){
for(int i=0;i<4;i++) c[i].clear();
for(int i=1;i<=cnt;i++){
if(vis[i]) continue;
c[a[i]%4].pb(mp(a[i],i));
}
int lst=c[1].size()?1:3;
pll fin=mp(0,0),ed=mp(0,0);
while(1){
if(c[0].size()>=2){
pll x1=c[0].back(); c[0].pop_back();
pll x2=c[0].back(); c[0].pop_back();
pll y=c[2].back(); c[2].pop_back();
if((x1.fi+y.fi)/2%4!=lst){
fin=merge(x1,y);
break;
}
else if((x2.fi+y.fi)/2%4!=lst){
fin=merge(x2,y);
break;
}
else{
c[2].pb(y);
c[0].pb(merge(x1,x2));
}
}
else if(c[2].size()>=2){
pll x1=c[2].back(); c[2].pop_back();
pll x2=c[2].back(); c[2].pop_back();
pll y=c[0].back(); c[0].pop_back();
if((x1.fi+y.fi)/2%4!=lst){
fin=merge(x1,y);
break;
}
else if((x2.fi+y.fi)/2%4!=lst){
fin=merge(x2,y);
break;
}
else{
c[0].pb(y);
c[2].pb(merge(x1,x2));
}
}
else{
ed=merge(c[0][0],c[2][0]);
break;
}
}
if(fin.se){
if(c[1].size()) merge(c[1][0],fin);
else merge(c[3][0],fin);
}
else{
if(c[1].size()) merge(c[1][0],ed);
else merge(c[3][0],ed);
}
}
b[2][0].clear(),b[2][2].clear();
for(int i=1;i<=cnt;i++){
if(vis[i]) continue;
b[2][a[i]%4].pb(a[i]);
}
// cout<<"test ";
// for(int i=1;i<=cnt;i++) if(!vis[i]) cout<<a[i]<<' ';
// cout<<endl;
for(auto r:ans) printf("%lld %lld\n",r.fi,r.se);
while(1){
if(b[2][0].size()+b[2][2].size()==1) break;
if(b[2][0].size()>=2){
ll x=b[2][0].back(); b[2][0].pop_back();
ll y=b[2][0].back(); b[2][0].pop_back();
printf("%lld %lld\n",x,y);
b[2][(x+y)/2%4].pb((x+y)/2);
}
else if(b[2][2].size()>=2){
ll x=b[2][2].back(); b[2][2].pop_back();
ll y=b[2][2].back(); b[2][2].pop_back();
printf("%lld %lld\n",x,y);
b[2][(x+y)/2%4].pb((x+y)/2);
}
else{
printf("%lld %lld\n",b[2][0][0],b[2][2][0]);
break;
}
}
}
int main(){
int T=readint();
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
99 4 739880851158065302 19206582949872932 883064254701115295 222072661880779376 7 148399819461615003 209088712310207988 53191076581680214 445068618251612752 230505279594622109 115754892157516718 804173775829453588 2 77979357045500669 41693388829622019 3 341612949433488278 609808714829036935 19994167...
output:
19206582949872932 739880851158065302 883064254701115295 379543717053969117 222072661880779376 631303985877542206 230505279594622109 148399819461615003 189452549528118556 804173775829453588 496813162678786072 445068618251612752 470940890465199412 209088712310207988 115754892157516718 5319107658168021...
result:
Subtask #2:
score: 0
Wrong Answer
Test #16:
score: 0
Wrong Answer
time: 0ms
memory: 10684kb
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 1 3 4 4 4 2 1 3 4 4 2 2 2 2 4 2 4 2 1 3 0 2 0 0 0 2 1 3 3 3 3 0 4 2 1 3 0 2 -1 1 3 2 2 4 2 3 3 0 2 3 1 4 0 2 2 4 2 0 2 3 1 4 2 4 2 1 3 4 0 2 2 2 2 2 2 3 3 3 3 3 0 0 0 0 2 1 1 0 2 1 3 4 4 4 2 3 3 3 0 4 2 1 3 0 2 1 3 4 0 2 2 4 2 4 0 2 2 2 2 4 2 0 2 1 1 0 2 4 2 1 3 0 4 2 2 4 2 1 1 3 3 3 0 4 2 1 3...
result:
wrong answer (3 + 0) is not an even number! (test case 7)
Subtask #3:
score: 0
Wrong Answer
Test #34:
score: 0
Wrong Answer
time: 82ms
memory: 11204kb
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 412630558152319488 622703684108675696 472135077337628566 658897822238868978 565516449788248772 517667121130497...
result:
wrong answer you didn't find a solution but jury did (test case 3)
Subtask #4:
score: 0
Runtime Error
Test #46:
score: 0
Runtime Error
input:
100 211957 911918942087402387 344230223346742784 16289402153237664 528890583619159010 886281719684850237 865484734102017297 321851390502278959 754268375474197153 237414161302130571 135637002716682378 824412491959977735 162505521049217610 246319278060116103 666703181591704279 650875500699154233 96397...
output:
591082823267833997 750673279799819289 749387671911821385 187498294172452641 468442983042137013 879124196035748105 426735945178329817 352902446225784261 214601964646700029 915796992992417549 565199478819558789 698044824174526233 707988272077429753 702915390242122313 705451831159776033 602615437195119...