QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#117169 | #6667. Prosjek | csy2005 | 0 | 0ms | 0kb | C++14 | 3.8kb | 2023-06-30 15:41:00 | 2023-06-30 15:41:03 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#include<cassert>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(((long long)(n))-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();++itr)
#define pb push_back
#define mk make_pair
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define spln(i,n) (i==n?'\n':' ')
#define fac_init(n){fac[0]=fac[1]=inv[1]=fi[0]=fi[1]=1;fz(i,2,n){fac[i]=1ll*fac[i-1]*i%mod;inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;fi[i]=1ll*fi[i-1]*inv[i]%mod;}}
using namespace std;
typedef long long i64;
typedef long double f80;
typedef unsigned int u32;
typedef unsigned long long u64;
//typedef __int128 i128;
//typedef unsigned __int128 u128;
#ifndef ONLINE_JUDGE
FILE *___=freopen("1.in","r",stdin);
#endif
inline void read(int &x)
{
char c;int f=1;
while(!isdigit(c=getchar()))if(c=='-')f=-1;
x=(c&15);while(isdigit(c=getchar()))x=(x<<1)+(x<<3)+(c&15);
x*=f;
}
inline void read(i64 &x)
{
char c;int f=1;
while(!isdigit(c=getchar()))if(c=='-')f=-1;
x=(c&15);while(isdigit(c=getchar()))x=(x<<1)+(x<<3)+(c&15);
x*=f;
}
int t,n,m,i,j;
vector<i64> a;
vector<i64> v0,v1;
vector<pair<i64,i64> > cur;
bool hv;
void dfs()
{
if(a.size()==1){
hv=1;return;
}
int i,j;
fz0k(i,a.size())fz(j,i+1,a.size()-1)if((a[i]+a[j])%2==0){
i64 ti=a[i],tj=a[j],tk=a.back();
cur.push_back(make_pair(a[i],a[j]));
a[i]=(a[i]+a[j])/2;
swap(a[j],a.back());a.pop_back();
dfs();if(hv)return;
a.push_back(tk);a[i]=ti;a[j]=tj;
cur.pop_back();
}
}
i64 solve0(vector<i64> a)
{
vector<i64> v0,v1;
ff(a,it) if((*it)%4<2)v0.push_back(*it);else v1.push_back(*it);
while(v0.size()>=2||v1.size()>=2){
if(v0.size()>=2){
i64 x=v0.back();v0.pop_back();
i64 y=v0.back();v0.pop_back();
printf("%lld %lld\n",x,y);
i64 t=(x+y)/2;if(t%4<2)v0.push_back(t);else v1.push_back(t);
}
else{
i64 x=v1.back();v1.pop_back();
i64 y=v1.back();v1.pop_back();
printf("%lld %lld\n",x,y);
i64 t=(x+y)/2;if(t%4<2)v0.push_back(t);else v1.push_back(t);
}
}
i64 res;
if(v0.size()&&v1.size()) printf("%lld %lld\n",v0.back(),v1.back()),res=(v0.back()+v1.back())/2;
else res=(v0.empty()?v1.back():v0.back());
return res;
}
bool solve(vector<i64> v,int d)
{
if(d>62) return 0;
if(v.size()<=d) return 0;
vector<i64> v0,v1;
ff(v,it)if(((*it)>>d)&1) v1.push_back(*it); else v0.push_back(*it);
if(v0.empty()||v1.empty()) return solve(v,d+1);
a.clear();a.push_back(v0.back());v0.pop_back();a.push_back(v1.back());v1.pop_back();
v.clear();ff(v0,it)v.push_back(*it);ff(v1,it)v.push_back(*it);
a.push_back(solve0(v));return 1;
}
int main()
{
read(t);
while(t--){
a.clear();
read(n);fz1(i,n){i64 x;read(x);a.push_back(x);}
cerr<<n<<endl;
vector<i64> v0,v1;
ff(a,it)if((*it)&1)v1.push_back(*it);else v0.push_back(*it);
if(v0.empty()||v1.empty()){
solve0(a);
continue;
}
int _;fz0k(_,2){
if(solve(v0,1)){
ff(v1,it) a.push_back(*it);
break;
}
swap(v0,v1);
}
if(_==2){puts("-1");continue;}
hv=0;cur.clear();dfs();
assert(hv);ff(cur,it) printf("%lld %lld\n",it->first,it->second);
}
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:
739880851158065302 19206582949872932 379543717053969117 883064254701115295 222072661880779376 631303985877542206 445068618251612752 209088712310207988 327078665280910370 53191076581680214 804173775829453588 115754892157516718 459964333993485153 148399819461615003 304182076727550078 19013487093129529...
result:
Subtask #2:
score: 0
Runtime Error
Test #16:
score: 0
Runtime Error
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
result:
Subtask #3:
score: 0
Time Limit Exceeded
Test #34:
score: 0
Time Limit Exceeded
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:
Subtask #4:
score: 0
Time Limit Exceeded
Test #46:
score: 0
Time Limit Exceeded
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...