QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#421163 | #6667. Prosjek | Nahidameow | 0 | 0ms | 0kb | C++20 | 1.8kb | 2024-05-25 14:34:16 | 2024-05-25 14:34:17 |
answer
#include<bits/stdc++.h>
#define pd push_back
#define all(A) A.begin(),A.end()
#define lb lower_bound
#define ve std::vector
typedef long long ll;
typedef long long ll;
typedef __int128 Int;
typedef unsigned long long ul;
typedef long double LD;
bool FileIfstream(std::string name){
std::ifstream f(name.c_str());
return f.good();
}
namespace Math{
ll QP(ll x,ll y,ll mod){ll ans=1;for(;y;y>>=1,x=x*x%mod)if(y&1)ans=ans*x%mod;return ans;}
ll inv(ll x,ll mod){return QP(x,mod-2,mod);}
}
const int N=2e5+10;
const int mod=998244353;
std::mt19937_64 rnd(time(NULL));
void solve(){
//don't forget to open long long
int n;std::cin>>n;
ve<ll>v(n+1);
for(int i=1;i<=n;i++)
std::cin>>v[i];
int T;
if(n<=10)T=400;
else if(n<=100)T=100;
else if(n<=1e4)T=50;
else if(n<=1e5)T=20;
else T=3;
while(T--){
std::multiset<std::pair<ul,ll>>st[2];
for(int i=1;i<=n;i++)
st[v[i]&1].insert({rnd(),v[i]});
ve<std::array<ll,2>>ans;
bool flg=true;
while(st[0].size()+st[1].size()>1){
if(st[0].size()==1&&st[1].size()==1){
flg=false;
break;
}
int p;
if(st[0].size()<=1)p=1;
else if(st[1].size()<=1)p=0;
else p=rnd()&1;
auto x=*st[p].begin();st[p].erase(st[p].find(x));
auto y=*st[p].begin();st[p].erase(st[p].find(y));
st[((x.second+y.second)/2)&1].insert({rnd(),(x.second+y.second)/2});
ans.pd({x.second,y.second});
}
if(flg){
for(auto &p:ans)
std::cout<<p[0]<<' '<<p[1]<<'\n';
return;
}
}
std::cout<<-1<<'\n';
}
int main(){
freopen("cow.in","r",stdin);
freopen("cow.out","w",stdout);
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int T=1;
std::cin>>T;
while(T--)solve();
#ifndef ONLINE_JUDGE
std::cerr<<std::fixed<<std::setprecision(10)<<1.0*clock()/CLOCKS_PER_SEC<<'\n';
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Dangerous Syscalls
Test #1:
score: 0
Dangerous Syscalls
input:
99 4 739880851158065302 19206582949872932 883064254701115295 222072661880779376 7 148399819461615003 209088712310207988 53191076581680214 445068618251612752 230505279594622109 115754892157516718 804173775829453588 2 77979357045500669 41693388829622019 3 341612949433488278 609808714829036935 19994167...
output:
result:
Subtask #2:
score: 0
Dangerous Syscalls
Test #16:
score: 0
Dangerous Syscalls
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:
result:
Subtask #3:
score: 0
Dangerous Syscalls
Test #34:
score: 0
Dangerous Syscalls
input:
100000 5 846784256447769304 457696478728961702 128469521648960690 597630796847754190 104256763714529164 5 658897822238868978 472135077337628566 399538027669313322 622703684108675696 425723088635325654 5 917704960887390986 140817562615382054 877934664521057998 782212806618666818 616380973421914538 8 ...
output:
result:
Subtask #4:
score: 0
Dangerous Syscalls
Test #46:
score: 0
Dangerous Syscalls
input:
100 211957 911918942087402387 344230223346742784 16289402153237664 528890583619159010 886281719684850237 865484734102017297 321851390502278959 754268375474197153 237414161302130571 135637002716682378 824412491959977735 162505521049217610 246319278060116103 666703181591704279 650875500699154233 96397...