QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#125760 | #6667. Prosjek | AFewSuns | 0 | 311ms | 19360kb | C++14 | 5.4kb | 2023-07-17 15:41:59 | 2023-07-17 15:42:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define ll long long
#define bl bool
ll my_pow(ll a,ll b,ll mod){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll qpow(ll a,ll b){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
#define db double
#define pf printf
#define pc putchar
#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
#define go(u) for(ll i=head[u];i;i=e[i].nxt)
#define enter pc('\n')
#define space pc(' ')
#define fir first
#define sec second
#define MP make_pair
#define il inline
#define inf 1e18
#define random(x) rand()*rand()%(x)
#define inv(a,mod) my_pow((a),(mod-2),(mod))
il ll read(){
ll sum=0,f=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
sum=sum*10+(ch^48);
ch=getchar();
}
return sum*f;
}
il void write(ll x){
if(x<0){
x=-x;
pc('-');
}
if(x>9) write(x/10);
pc(x%10+'0');
}
il void writeln(ll x){
write(x);
enter;
}
il void writesp(ll x){
write(x);
space;
}
}
using namespace my_std;
vector<pair<ll,ll> > ans;
vector<ll> A,B,S0,S2;
ll t,n,c[1000010];
il void solve1(){
S0.clear();
S2.clear();
fr(i,1,n){
if(c[i]%4==0) S0.push_back(c[i]);
else S2.push_back(c[i]);
}
while(1){
if((ll)S0.size()>=2){
ll x=S0.back(),y;
S0.pop_back();
y=S0.back();
S0.pop_back();
ans.push_back(MP(x,y));
if(((x+y)/2)%4==0) S0.push_back((x+y)/2);
else S2.push_back((x+y)/2);
continue;
}
if((ll)S2.size()>=2){
ll x=S2.back(),y;
S2.pop_back();
y=S2.back();
S2.pop_back();
ans.push_back(MP(x,y));
if(((x+y)/2)%4==0) S0.push_back((x+y)/2);
else S2.push_back((x+y)/2);
continue;
}
break;
}
if(!S0.empty()&&!S2.empty()) ans.push_back(MP(S0[0],S2[0]));
}
il bl chk0(){
ll d=0;
fr(i,1,60){
bl ck=0;
fr(j,0,(ll)B.size()-1) if(((B[j]>>i)&1)!=((B[0]>>i)&1)) ck=1;
if(ck){
d=i;
break;
}
}
if(!d) return 0;
ll id=0;
fr(i,0,(ll)B.size()-1) if((B[i]>>d)&1) id=i;
swap(B[(ll)B.size()-1],B[id]);
fr(i,0,(ll)B.size()-1) if(!((B[i]>>d)&1)) id=i;
swap(B[(ll)B.size()-2],B[id]);
pfr(i,d-1,1){
if((ll)B.size()<=2) return 0;
ll x=B.back(),y;
B.pop_back();
y=B.back();
B.pop_back();
ans.push_back(MP(x,y));
B.push_back((x+y)/2);
}
return 1;
}
il bl chk1(){
fr(i,0,(ll)ans.size()-1){
ans[i].fir++;
ans[i].sec++;
}
swap(A,B);
fr(i,0,(ll)A.size()-1) A[i]++;
fr(i,0,(ll)B.size()-1) B[i]++;
return chk0();
}
il void solve2(){
ll a=0,b=0;
fr(i,0,(ll)B.size()-1) if(B[i]%4==0) a=i;
swap(B[(ll)B.size()-1],B[a]);
fr(i,0,(ll)B.size()-1) if(B[i]%4==2) b=i;
swap(B[(ll)B.size()-2],B[b]);
a=B.back();
B.pop_back();
b=B.back();
B.pop_back();
while(1){
if((ll)A.size()>=2){
ll x=A.back(),y;
A.pop_back();
y=A.back();
A.pop_back();
ans.push_back(MP(x,y));
if(((x+y)/2)&1) A.push_back((x+y)/2);
else B.push_back((x+y)/2);
continue;
}
if((ll)B.size()>=2){
ll x=B.back(),y;
B.pop_back();
y=B.back();
B.pop_back();
ans.push_back(MP(x,y));
if(((x+y)/2)&1) A.push_back((x+y)/2);
else B.push_back((x+y)/2);
continue;
}
break;
}
if(A.empty()){
if(B[0]%4==0){
ans.push_back(MP(a,B[0]));
ans.push_back(MP((a+B[0])/2,b));
}
else{
ans.push_back(MP(b,B[0]));
ans.push_back(MP((b+B[0])/2,a));
}
}
else if(B.empty()){
ans.push_back(MP(a,b));
ans.push_back(MP((a+b)/2,A[0]));
}
else{
if(B[0]%4==0){
if((a/4+b/4+A[0]/2)&1){
ans.push_back(MP(a,b));
ans.push_back(MP((a+b)/2,A[0]));
ans.push_back(MP(((a+b)/2+A[0])/2,B[0]));
}
else if((B[0]/4+b/4+A[0]/2)&1){
ans.push_back(MP(B[0],b));
ans.push_back(MP((B[0]+b)/2,A[0]));
ans.push_back(MP(((B[0]+b)/2+A[0])/2,a));
}
else{
ans.push_back(MP(a,B[0]));
ans.push_back(MP((a+B[0])/2,b));
ans.push_back(MP(((a+B[0])/2+b)/2,A[0]));
}
}
else{
if((a/4+b/4+A[0]/2)&1){
ans.push_back(MP(a,b));
ans.push_back(MP((a+b)/2,A[0]));
ans.push_back(MP(((a+b)/2+A[0])/2,B[0]));
}
else if((a/4+B[0]/4+A[0]/2)&1){
ans.push_back(MP(a,B[0]));
ans.push_back(MP((a+B[0])/2,A[0]));
ans.push_back(MP(((a+B[0])/2+A[0])/2,b));
}
else{
ans.push_back(MP(b,B[0]));
ans.push_back(MP((b+B[0])/2,a));
ans.push_back(MP(((b+B[0])/2+a)/2,A[0]));
}
}
}
}
il void clr(){
ans.clear();
A.clear();
B.clear();
}
int main(){
t=read();
writeln(t);
while(t--){
n=read();
writeln(n);
fr(i,1,n) c[i]=read();
fr(i,1,n) writesp(c[i]);
enter;
fr(i,1,n){
if(c[i]&1) A.push_back(c[i]);
else B.push_back(c[i]);
}
if(A.empty()){
solve1();
fr(i,0,(ll)ans.size()-1) pf("%lld %lld\n",ans[i].fir,ans[i].sec);
}
else if(B.empty()){
fr(i,1,n) c[i]++;
solve1();
fr(i,0,(ll)ans.size()-1) pf("%lld %lld\n",ans[i].fir-1,ans[i].sec-1);
}
else if(chk0()){
solve2();
fr(i,0,(ll)ans.size()-1) pf("%lld %lld\n",ans[i].fir,ans[i].sec);
}
else if(chk1()){
solve2();
fr(i,0,(ll)ans.size()-1) pf("%lld %lld\n",ans[i].fir-1,ans[i].sec-1);
}
else writeln(-1);
clr();
}
}
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: 3644kb
input:
99 4 739880851158065302 19206582949872932 883064254701115295 222072661880779376 7 148399819461615003 209088712310207988 53191076581680214 445068618251612752 230505279594622109 115754892157516718 804173775829453588 2 77979357045500669 41693388829622019 3 341612949433488278 609808714829036935 19994167...
output:
99 4 739880851158065302 19206582949872932 883064254701115295 222072661880779376 19206582949872932 739880851158065302 379543717053969117 883064254701115295 631303985877542206 222072661880779376 7 148399819461615003 209088712310207988 53191076581680214 445068618251612752 230505279594622109 1157548921...
result:
wrong answer (99 + 4) is not an even number! (test case 1)
Subtask #2:
score: 0
Wrong Answer
Test #16:
score: 0
Wrong Answer
time: 1ms
memory: 3532kb
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:
100 3 3 3 2 -1 3 4 1 1 -1 4 1 3 4 4 4 4 3 1 2 4 6 4 4 2 3 1 2 1 3 2 2 2 4 4 2 3 3 4 0 2 1 4 4 2 3 1 2 0 3 0 2 0 0 0 0 2 7 3 3 1 1 3 4 0 4 0 1 3 2 2 3 3 3 1 2 2 2 0 4 4 0 4 1 4 2 3 3 1 2 2 2 4 7 4 0 0 3 2 3 4 3 3 0 0 0 4 2 2 2 4 3 3 4 4 2 0 3 0 2 1 3 2 4 7 0 2 2 1 4 2 4 4 2 3 1 2 2 2 0 4 ...
result:
wrong answer (100 + 3) is not an even number! (test case 1)
Subtask #3:
score: 0
Wrong Answer
Test #34:
score: 0
Wrong Answer
time: 152ms
memory: 3724kb
input:
100000 5 846784256447769304 457696478728961702 128469521648960690 597630796847754190 104256763714529164 5 658897822238868978 472135077337628566 399538027669313322 622703684108675696 425723088635325654 5 917704960887390986 140817562615382054 877934664521057998 782212806618666818 616380973421914538 8 ...
output:
100000 5 846784256447769304 457696478728961702 128469521648960690 597630796847754190 104256763714529164 104256763714529164 846784256447769304 475520510081149234 597630796847754190 128469521648960690 457696478728961702 293083000188961196 536575653464451712 5 658897822238868978 472135077337628566 399...
result:
wrong answer (100000 + 5) is not an even number! (test case 1)
Subtask #4:
score: 0
Wrong Answer
Test #46:
score: 0
Wrong Answer
time: 311ms
memory: 19360kb
input:
100 211957 911918942087402387 344230223346742784 16289402153237664 528890583619159010 886281719684850237 865484734102017297 321851390502278959 754268375474197153 237414161302130571 135637002716682378 824412491959977735 162505521049217610 246319278060116103 666703181591704279 650875500699154233 96397...
output:
100 211957 911918942087402387 344230223346742784 16289402153237664 528890583619159010 886281719684850237 865484734102017297 321851390502278959 754268375474197153 237414161302130571 135637002716682378 824412491959977735 162505521049217610 246319278060116103 666703181591704279 650875500699154233 96397...
result:
wrong answer (100 + 211957) is not an even number! (test case 1)