QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#117453 | #6667. Prosjek | zhouhuanyi | 0 | 174ms | 22148kb | C++11 | 3.6kb | 2023-07-01 11:19:26 | 2023-07-01 11:19:27 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#define N 1000000
using namespace std;
long long read()
{
char c=0;
long long sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
struct reads
{
long long x,y;
};
reads dque[N+1];
int T,n,top,length,length2,leng;
long long a[N+1],tong[N+1],tong2[N+1],tmp[N+1];
bool opt;
void solve(vector<long long>p)
{
if (p.size()==1)
{
opt=1;
for (int i=1;i<=top;++i) printf("%lld %lld\n",dque[i].x,dque[i].y);
return;
}
vector<long long>q;
for (int i=0;i<p.size();++i)
for (int j=i+1;j<p.size();++j)
if (!((p[i]+p[j])&1))
{
q.clear(),dque[++top]=(reads){p[i],p[j]},q.push_back((p[i]+p[j])>>1);
for (int k=0;k<p.size();++k)
if (k!=i&&k!=j)
q.push_back(p[k]);
solve(q),top--;
if (opt) return;
}
return;
}
int main()
{
int rt,rt2,x,y;
long long tops,tops2;
bool op,op2;
queue<long long>A;
queue<long long>B;
vector<long long>p;
T=read();
while (T--)
{
n=read(),length=length2=opt=top=0;
for (int i=1;i<=n;++i)
{
a[i]=read();
if (!(a[i]&1)) tong[++length]=a[i];
else tong2[++length2]=a[i];
}
rt=0;
for (int i=1;i<=min(59,length-1);++i)
{
op=op2=0;
for (int j=1;j<=length;++j)
{
if (!(tong[j]&(1ll<<i))) op=1;
else op2=1;
}
if (op&&op2)
{
rt=i;
break;
}
}
rt2=0;
for (int i=1;i<=min(59,length2-1);++i)
{
op=op2=0;
for (int j=1;j<=length2;++j)
{
if (!(tong2[j]&(1ll<<i))) op=1;
else op2=1;
}
if (op&&op2)
{
rt2=i;
break;
}
}
for (int i=rt;i>=1;--i)
{
leng=x=y=0;
for (int j=1;j<=length;++j)
{
if (!(tong[j]&(1ll<<i))) x=j;
else y=j;
}
dque[++top]=(reads){tong[x],tong[y]};
for (int j=1;j<=length;++j)
if (j!=x&&j!=y)
tmp[++leng]=tong[j];
tmp[++leng]=(tong[x]+tong[y])>>1,length=leng;
for (int j=1;j<=length;++j) tong[j]=tmp[j];
}
for (int i=rt2;i>=1;--i)
{
leng=x=y=0;
for (int j=1;j<=length2;++j)
{
if (!(tong2[j]&(1ll<<i))) x=j;
else y=j;
}
dque[++top]=(reads){tong2[x],tong2[y]};
for (int j=1;j<=length2;++j)
if (j!=x&&j!=y)
tmp[++leng]=tong2[j];
tmp[++leng]=(tong2[x]+tong2[y])>>1,length2=leng;
for (int j=1;j<=length2;++j) tong2[j]=tmp[j];
}
for (int i=1;i<=length;++i)
{
if (tong[i]%4==0) A.push(tong[i]);
else B.push(tong[i]);
}
while (A.size()>=3||B.size()>=3)
{
if (A.size()>=3) tops=A.front(),A.pop(),tops2=A.front(),A.pop();
else tops=B.front(),B.pop(),tops2=B.front(),B.pop();
dque[++top]=(reads){tops,tops2};
if (((tops+tops2)>>1)%4==0) A.push((tops+tops2)>>1);
else B.push((tops+tops2)>>1);
}
length=0;
while (!A.empty()) tong[++length]=A.front(),A.pop();
while (!B.empty()) tong[++length]=B.front(),B.pop();
for (int i=1;i<=length2;++i)
{
if (tong2[i]%4==1) A.push(tong2[i]);
else B.push(tong2[i]);
}
while (A.size()>=3||B.size()>=3)
{
if (A.size()>=3) tops=A.front(),A.pop(),tops2=A.front(),A.pop();
else tops=B.front(),B.pop(),tops2=B.front(),B.pop();
dque[++top]=(reads){tops,tops2};
if (((tops+tops2)>>1)%4==1) A.push((tops+tops2)>>1);
else B.push((tops+tops2)>>1);
}
while (!A.empty()) tong[++length]=A.front(),A.pop();
while (!B.empty()) tong[++length]=B.front(),B.pop();
p.clear();
for (int i=1;i<=length;++i) p.push_back(tong[i]);
solve(p);
if (!opt) puts("-1");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 11772kb
input:
99 4 739880851158065302 19206582949872932 883064254701115295 222072661880779376 7 148399819461615003 209088712310207988 53191076581680214 445068618251612752 230505279594622109 115754892157516718 804173775829453588 2 77979357045500669 41693388829622019 3 341612949433488278 609808714829036935 19994167...
output:
-1 804173775829453588 115754892157516718 230505279594622109 148399819461615003 209088712310207988 445068618251612752 327078665280910370 189452549528118556 258265607404514463 459964333993485153 359114970698999808 53191076581680214 77979357045500669 41693388829622019 199941674506573816 341612949433488...
result:
wrong answer you didn't find a solution but jury did (test case 1)
Subtask #2:
score: 0
Wrong Answer
Test #16:
score: 0
Wrong Answer
time: 2ms
memory: 11836kb
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 4 2 1 3 2 2 2 4 3 3 4 2 3 1 2 0 -1 1 3 3 3 4 0 2 2 1 3 2 2 0 4 -1 4 2 4 0 0 2 3 3 3 3 3 1 0 2 1 3 2 4 4 2 2 2 0 4 2 2 3 1 2 2 0 2 1 3 3 3 0 2 1 1 1 3 1 3 4 4 4 2 4 2 1 3 0 2 3 3 3 1 -1 4 2 0 2 1 3 2 4 0 2 1 1 4 2 4 4 0 4 3 1 2 2 4 2 1 3 4 2 3 3 3 3 3 1 0 4 4 2 3 1 1 1 0 4 0 2 1 3 2...
result:
wrong answer you didn't find a solution but jury did (test case 6)
Subtask #3:
score: 0
Wrong Answer
Test #34:
score: 0
Wrong Answer
time: 101ms
memory: 9796kb
input:
100000 5 846784256447769304 457696478728961702 128469521648960690 597630796847754190 104256763714529164 5 658897822238868978 472135077337628566 399538027669313322 622703684108675696 425723088635325654 5 917704960887390986 140817562615382054 877934664521057998 782212806618666818 616380973421914538 8 ...
output:
-1 622703684108675696 425723088635325654 658897822238868978 472135077337628566 565516449788248772 399538027669313322 482527238728781047 524213386372000675 -1 571151272187977852 655064257540479734 244724447292237728 930867290080315972 579752694340986386 506671523510380578 839457827735616722 613107764...
result:
wrong answer you didn't find a solution but jury did (test case 1)
Subtask #4:
score: 0
Wrong Answer
Test #46:
score: 0
Wrong Answer
time: 174ms
memory: 22148kb
input:
100 211957 911918942087402387 344230223346742784 16289402153237664 528890583619159010 886281719684850237 865484734102017297 321851390502278959 754268375474197153 237414161302130571 135637002716682378 824412491959977735 162505521049217610 246319278060116103 666703181591704279 650875500699154233 96397...
output:
187349684646959176 543486620620520822 591082823267833997 532418085391726079 344230223346742784 16289402153237664 249254979345412696 312772601466767068 411124119364554092 742729082115741192 328378031127309040 140593778890078108 496306822172706836 795972847417009120 180430902116578580 9880494204801185...
result:
wrong answer (365418152633739999 + 281013790406089882) is not an even number! (test case 1)