QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#59965#1845. PermuteAFewSunsTL 335ms3784kbC++5.0kb2022-11-02 10:48:042022-11-02 10:48:06

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-02 10:48:06]
  • 评测
  • 测评结果:TL
  • 用时:335ms
  • 内存:3784kb
  • [2022-11-02 10:48:04]
  • 提交

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 8e18
	#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; 
ll t,aa[11],a[11],id[11],b[8]={0,1,4,6,5,2},pw[8]={1,3,2,6,4,5};
ll p[22],cnt,nd,q[22],res[22];
bl ck[22],pd;
il bl cmp(ll x,ll y){
	return a[x]<a[y];
}
void dfs(ll now){
	if(now==cnt){
		if(!nd){
			pd=1;
			fr(i,1,cnt) res[i]=q[cnt-i+1];
		}
		return;
	}
	now++;
	fr(i,1,cnt){
		if(ck[i]) continue;
		ck[i]=1;
		nd=(nd+p[i]*pw[(now-1)%6]%7)%7;
		q[now]=p[i];
		dfs(now);
		ck[i]=0;
		nd=(nd-p[i]*pw[(now-1)%6]%7+7)%7;
	}
}
void prf(ll x,ll y){
	if(!x) return;
	if(aa[y]>=x){
		ans.push_back(MP(x,y));
		aa[y]-=x;
	}
	else{
		if(aa[y]) ans.push_back(MP(aa[y],y));
		ans.push_back(MP(x-aa[y],y+7));
		aa[y]=0;
		aa[y+7]-=x-aa[y];
	}
}
void prtf(){
	writeln(ans.size());
	fr(i,0,(ll)ans.size()-1) pf("%lld %lld\n",ans[i].fir,ans[i].sec);
}
int main(){
	t=read();
	while(t--){
		ans.clear();
		ll div=0;
		fr(i,0,6) a[i]=0;
		fr(i,0,9){
			aa[i]=read();
			a[i%7]+=aa[i];
		}
		fr(i,0,6) if(a[i]) id[++div]=i;
		sort(id+1,id+div+1,cmp);
		if(div==1){
			ll tmp=b[a[id[1]]%6]*id[1]%7;
			if(tmp) writeln(-1);
			else{
				prf(a[id[1]],id[1]);
				prtf();
			}
			continue;
		}
		if(div>=4){
			fr(i,1,4) a[id[i]]--;
			ll tmp=pw[4],tot=0;
			nd=0;
			fr(i,1,div){
				if(!a[id[i]]) continue;
				nd=(nd+b[a[id[i]]%6]*tmp*id[i]%7)%7;
				tmp=tmp*pw[a[id[i]]%6]%7;
				tot++;
			}
			pfr(i,div,1) if(a[id[i]]) prf(a[id[i]],id[i]);
			cnt=4;
			fr(i,1,4) p[i]=id[i];
			fr(i,1,4) ck[i]=0;
			dfs(0);
			fr(i,1,4) prf(1,res[i]);
			prtf();
			continue;
		}
		if(div==3&&a[id[3]]>=5){
			fr(i,1,2) a[id[i]]--;
			a[id[3]]-=5;
			ll tmp=pw[1],tot=0;
			nd=0;
			fr(i,1,div){
				if(!a[id[i]]) continue;
				nd=(nd+b[a[id[i]]%6]*tmp*id[i]%7)%7;
				tmp=tmp*pw[a[id[i]]%6]%7;
				tot++;
			}
			pfr(i,div,1) if(a[id[i]]) prf(a[id[i]],id[i]);
			cnt=7;
			fr(i,1,7) p[i]=id[min(3ll,i)];
			fr(i,1,7) ck[i]=0;
			dfs(0);
			fr(i,1,7) prf(1,res[i]);
			prtf();
			continue;
		}
		if(div==3&&a[id[2]]>=2&&a[id[3]]>=2){
			fr(i,1,3) a[id[i]]-=min(2ll,i);
			ll tmp=pw[5],tot=0;
			nd=0;
			fr(i,1,div){
				if(!a[id[i]]) continue;
				nd=(nd+b[a[id[i]]%6]*tmp*id[i]%7)%7;
				tmp=tmp*pw[a[id[i]]%6]%7;
				tot++;
			}
			pfr(i,div,1) if(a[id[i]]) prf(a[id[i]],id[i]);
			cnt=5;
			fr(i,1,5) p[i]=id[(i+2)/2];
			fr(i,1,5) ck[i]=0;
			dfs(0);
			fr(i,1,5) prf(1,res[i]);
			prtf();
			continue;
		}
		if(div==2&&a[id[1]]>=2&&a[id[2]]>=3){
			fr(i,1,2) a[id[i]]-=i+1;
			ll tmp=pw[5],tot=0;
			nd=0;
			fr(i,1,div){
				if(!a[id[i]]) continue;
				nd=(nd+b[a[id[i]]%6]*tmp*id[i]%7)%7;
				tmp=tmp*pw[a[id[i]]%6]%7;
				tot++;
			}
			pfr(i,div,1) if(a[id[i]]) prf(a[id[i]],id[i]);
			cnt=5;
			fr(i,1,5) p[i]=id[(i+3)/3];
			fr(i,1,5) ck[i]=0;
			dfs(0);
			fr(i,1,5) prf(1,res[i]);
			prtf();
			continue;
		}
		if(div==2&&a[id[1]]==1){
			pd=0;
			fr(i,0,min(6ll,a[id[2]])){
				ll tmp=id[1]*pw[i%6]%7;
				tmp=(tmp+b[i%6]*id[2]%7)%7;
				tmp=(tmp+b[(a[id[2]]-i)%6]*pw[(i+1)%6]*id[2]%7)%7;
				if(!tmp){
					prf(a[id[2]]-i,id[2]);
					prf(1,id[1]);
					prf(i,id[2]);
					prtf();
					pd=1;
					break;
				}
			}
			if(!pd) writeln(-1);
			continue;
		}
		cnt=nd=0;
		fr(i,1,div) fr(j,1,a[id[i]]) p[++cnt]=id[i];
		fr(i,1,cnt) ck[i]=0;
		pd=0;
		dfs(0);
		if(!pd) writeln(-1);
		else{
			fr(i,1,cnt) prf(1,res[i]);
			prtf();
		}
	}
}
/*
3
1 2 3 4 1 2 1 1 0 0
0 0 1 1 1 0 0 1 0 0
0 1 0 2 0 1 0 0 2 0

3
0 0 1 0 5 0 0 1 0 0
0 2 0 0 3 0 6 0 0 0
0 0 0 0 1 0 4 5 0 0

3
0 0 2 0 0 1 0 2 0 0
0 3 0 0 4 0 4 0 0 0
0 0 0 2 0 3 0 0 2 0

3
0 0 3 0 0 2 0 0 0 0
0 4 0 0 3 0 0 0 0 0
0 0 0 5 0 0 0 0 7 0

3
0 1 0 0 1 0 0 0 0 0
0 2 0 0 0 0 1 0 0 1
0 1000000000 0 0 0 0 0 0 0 0
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3584kb

input:

3
0 1 0 0 1 0 0 0 0 0
0 2 0 0 0 0 1 0 0 1
0 1000000000 0 0 0 0 0 0 0 0

output:

2
1 1
1 4
4
1 9
1 6
1 1
1 1
-1

result:

ok T=3

Test #2:

score: 0
Accepted
time: 146ms
memory: 3784kb

input:

100000
0 0 0 1 0 1 1 1 0 1
1 1 0 0 1 0 1 0 1 0
1 1 1 1 0 0 0 1 0 1
0 1 1 0 0 1 1 1 1 0
0 0 1 0 1 0 1 0 1 0
0 1 0 0 0 0 0 1 0 0
1 1 0 0 0 0 0 0 1 1
1 0 1 1 1 0 1 0 0 0
0 1 1 0 0 1 0 1 0 1
1 0 0 1 1 0 0 1 0 0
1 1 0 1 0 0 1 0 1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2 6
...

result:

ok T=100000

Test #4:

score: 0
Accepted
time: 335ms
memory: 3640kb

input:

100000
1 3 3 2 3 0 2 1 3 2
3 1 2 0 0 3 1 0 0 1
3 2 0 2 0 2 0 1 3 1
0 1 0 3 1 1 0 3 0 2
2 2 2 3 3 3 1 0 3 0
0 3 0 2 0 3 2 0 2 3
3 0 1 1 3 3 2 1 3 1
1 2 3 0 1 2 2 0 2 3
3 1 0 3 2 0 2 3 1 0
2 1 2 3 0 2 2 3 1 2
3 3 0 3 0 0 1 1 1 1
1 3 1 0 2 1 0 3 3 3
3 0 0 3 3 2 3 3 2 1
3 3 3 1 0 2 3 0 2 3
3 3 1 3 3 2 3...

output:

12
3 1
3 8
3 2
2 9
2 4
1 6
1 3
1 0
1 3
1 7
1 6
1 4
7
3 5
2 2
2 0
1 6
1 1
1 9
1 0
9
2 1
3 8
3 0
1 5
1 3
1 5
1 3
1 9
1 7
7
3 3
3 7
1 9
1 1
1 5
1 9
1 4
11
2 1
3 8
3 5
3 4
2 3
1 2
1 0
1 0
1 6
1 2
1 3
10
3 1
2 8
2 5
2 9
1 6
1 3
1 5
1 3
1 6
1 9
11
3 0
1 7
3 5
3 4
2 8
1 6
1 2
1 6
1 3
1 8
1 9
10
3 2
3 9
2 1...

result:

ok T=100000

Test #5:

score: 0
Accepted
time: 298ms
memory: 3716kb

input:

100000
0 1 3 1 1 0 1 3 0 1
4 3 4 1 3 4 3 4 2 3
1 3 1 3 3 4 3 4 2 2
1 0 1 0 3 3 3 1 1 1
3 4 1 3 1 0 1 2 1 2
0 1 2 1 4 1 0 3 4 2
0 4 1 2 4 3 2 1 1 3
0 4 0 4 2 1 0 2 1 3
4 4 0 4 4 1 4 1 4 1
1 3 2 1 1 4 2 3 4 1
3 3 4 3 3 4 1 2 1 4
3 1 4 0 3 0 4 3 1 4
3 0 3 2 3 4 2 3 1 3
3 1 2 4 3 4 2 4 1 1
2 1 0 2 2 3 2...

output:

7
3 2
1 9
3 7
1 4
1 1
1 6
1 3
13
4 0
4 7
4 2
3 9
3 1
2 8
3 5
2 6
2 4
1 6
1 4
1 3
1 5
14
3 1
2 8
1 0
4 7
4 5
2 6
2 4
2 3
1 2
1 9
1 9
1 3
1 4
1 6
9
3 6
3 5
2 4
1 2
1 0
1 8
1 9
1 7
1 4
11
4 1
1 8
3 0
2 7
2 3
1 2
1 9
1 9
1 4
1 6
1 3
10
1 1
4 8
4 4
2 2
1 9
2 7
1 3
1 5
1 7
1 9
12
4 1
1 8
4 4
1 2
3 9
2 5
1...

result:

ok T=100000

Test #6:

score: 0
Accepted
time: 275ms
memory: 3644kb

input:

100000
0 2 1 4 1 4 1 1 3 4
2 3 3 1 3 4 2 1 1 1
1 2 1 3 3 1 1 5 0 0
1 4 0 3 1 1 0 0 0 4
4 3 5 0 0 0 4 2 5 1
3 2 5 1 2 5 0 0 0 1
2 0 5 3 1 3 0 5 1 3
0 2 5 4 5 5 1 1 1 0
1 3 1 4 4 5 2 2 2 1
2 1 2 1 0 0 1 2 5 1
0 2 0 4 5 4 5 2 0 3
5 3 5 5 2 2 4 0 5 5
3 4 2 2 5 1 5 0 3 4
0 3 3 0 5 3 3 4 3 5
0 3 5 4 3 3 4...

output:

10
1 2
4 9
2 1
3 8
4 5
3 3
1 6
1 7
1 4
1 3
12
4 5
3 2
1 9
3 1
1 8
2 4
2 0
1 6
1 3
1 4
1 6
1 7
9
1 0
5 7
3 4
3 3
1 1
1 2
1 6
1 5
1 1
7
4 9
4 1
2 3
1 0
1 4
1 5
1 3
10
3 1
4 8
5 2
4 0
1 7
3 6
1 6
1 7
1 9
1 8
10
5 2
1 9
5 5
2 0
1 4
1 1
1 4
1 3
1 1
1 0
10
5 2
3 9
2 0
5 7
2 5
2 3
1 4
1 3
1 8
1 5
9
5 5
5 4...

result:

ok T=100000

Test #7:

score: 0
Accepted
time: 270ms
memory: 3644kb

input:

100000
5 5 0 1 0 3 1 5 3 6
0 5 1 4 2 1 1 5 3 4
1 3 0 5 0 2 4 1 5 5
4 5 4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7
6 1
5 6
4 4
1 2
1 9
1 5
1 3
1 5
1 3
1 4
1 9
11
3 1
4 8
6 0
5 5
3 6
3 4
3 3
1 3
1 4
1 9
1 6
13
7 2
7 9
6 0
5 7
4 1
2 8
3 3
2 6
2 4
1 6
1 4
1 3
1 ...

result:

ok T=100000

Test #9:

score: 0
Accepted
time: 269ms
memory: 3684kb

input:

100000
7 3 4 5 2 6 6 3 6 0
8 3 8 6 5 1 8 2 7 7
5 1 8 4 7 0 1 1 1 0
1 1 8 7 8 0 6 2 3 7
5 2 1 3 5 8 4 5 1 0
8 7 7 5 3 3 3 6 5 6
4 1 5 0 7 8 0 8 1 4
5 2 6 5 5 2 0 6 8 2
3 0 0 1 7 2 3 1 3 5
2 4 1 3 7 3 3 3 1 5
2 7 8 2 1 8 0 2 1 7
1 5 7 8 1 6 2 3 6 2
0 0 1 6 7 6 8 2 2 0
4 0 3 1 4 3 0 4 7 5
3 3 7 0 6 8 8...

output:

13
7 0
3 7
3 1
6 8
6 6
5 5
4 3
3 2
1 4
1 4
1 5
1 2
1 3
13
8 2
7 9
3 1
7 8
8 0
2 7
7 6
5 3
4 4
1 5
1 3
1 4
1 6
9
8 2
7 4
5 0
3 3
1 1
1 7
1 6
1 8
1 3
13
8 2
7 9
8 4
6 3
5 6
1 1
2 8
1 0
1 7
1 7
1 8
1 3
1 6
11
5 0
5 7
8 5
5 4
3 6
2 3
2 1
1 8
1 2
1 3
1 6
14
8 0
6 7
7 2
6 9
7 1
5 8
4 3
2 6
2 5
2 4
1 4
1 5...

result:

ok T=100000

Test #10:

score: 0
Accepted
time: 251ms
memory: 3588kb

input:

100000
7 8 0 3 2 6 7 9 8 7
7 8 8 5 0 0 6 8 7 7
6 6 0 8 8 9 9 2 1 8
4 7 7 8 2 1 1 3 5 4
1 6 9 6 6 4 0 5 0 2
7 1 7 1 1 2 9 8 5 7
5 3 6 6 1 1 8 4 5 8
4 5 3 0 9 2 8 5 5 4
0 4 9 2 1 4 1 4 0 1
3 4 7 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
7 6
6 5
2 3...

result:

ok T=100000

Test #12:

score: 0
Accepted
time: 310ms
memory: 3752kb

input:

100000
494719969 120370150 440274545 51278543 770105708 138663251 867692060 230246532 162623412 131761825
16498099 70750104 350416959 359532393 346253463 539196901 104480711 629723297 27266106 267471731
320561715 423589912 850677494 604957917 815663121 8935553 252297110 812216267 821793396 495865924...

output:

14
867692060 6
770105708 4
494719969 0
230246532 7
440274545 2
131761824 9
120370150 1
162623411 8
138663250 5
51278542 3
1 8
1 3
1 5
1 9
14
16498099 0
629723297 7
350416959 2
267471731 9
539196901 5
359532392 3
346253462 4
104480710 6
70750104 1
27266105 8
1 6
1 8
1 3
1 4
14
850677494 2
495865924 9...

result:

ok T=100000

Test #13:

score: 0
Accepted
time: 53ms
memory: 3640kb

input:

100000
1 0 0 0 0 0 738556701 0 0 0
0 376417170 0 0 0 1 0 0 0 0
0 0 0 169526540 0 1 0 0 0 0
0 0 1 0 0 0 0 0 822697278 0
0 0 0 0 121828077 0 0 0 1 0
0 994528277 0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 0 0 771142048
0 0 0 0 0 77945594 0 0 1 0
1 0 0 0 963629977 0 0 0 0 0
0 0 0 1 0 805871384 0 0 0 0
0 0 0 0 306368...

output:

3
738556696 6
1 0
5 6
3
376417165 1
1 5
5 1
3
169526535 3
1 5
5 3
3
822697275 8
1 2
3 8
3
121828075 4
1 8
2 4
-1
3
771142045 9
1 6
3 9
3
77945590 5
1 8
4 5
3
963629973 4
1 0
4 4
2
805871384 5
1 3
-1
-1
-1
3
539154373 5
1 8
3 5
3
237082606 6
1 9
3 6
3
435427563 6
1 9
1 6
3
443844373 9
1 5
1 9
-1
-1
3...

result:

ok T=100000

Test #14:

score: -100
Time Limit Exceeded

input:

100000
2 969002522 0 0 0 0 0 0 0 0
0 0 0 902830660 0 0 2 0 0 0
0 0 0 0 1 0 216346913 0 1 0
365035921 0 0 0 0 0 0 0 1 1
0 0 0 447294079 0 0 0 0 2 0
173545560 0 0 0 0 0 0 1 0 1
236545965 1 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 2 0 104167147
1 0 94723253 1 0 0 0 0 0 0
0 1 0 0 0 474995039 0 0 0 1
0 0 0 1 0 0 0 ...

output:

6
969002519 1
1 1
1 1
1 0
1 0
1 1
6
902830657 3
1 6
1 3
1 3
1 6
1 3
8
216346908 6
1 4
1 8
1 6
1 6
1 6
1 6
1 6
8
365035916 0
1 9
1 8
1 0
1 0
1 0
1 0
1 0
6
447294076 3
1 3
1 8
1 3
1 8
1 3
-1
8
236545960 0
1 1
1 4
1 0
1 0
1 0
1 0
1 0
6
104167144 9
1 7
1 9
1 7
1 9
1 9
8
94723248 2
1 3
1 0
1 2
1 2
1 2
1 ...

result: