QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#59929#1845. PermuteAppleblue17TL 2ms3580kbC++14994b2022-11-02 09:28:422022-11-02 09:28:44

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 09:28:44]
  • 评测
  • 测评结果:TL
  • 用时:2ms
  • 内存:3580kb
  • [2022-11-02 09:28:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,mod=7;
int T,n;
int c[N],sum;
int p[N],id;


int ksm(int a,int x){
	int tot=1;
	while(x){
		if(x & 1ll) tot=tot*a%mod;
		a=a*a%mod;
		x>>=1ll;
	}
	return tot;
}



int main(){
	cin>>T;
	while(T--){
		sum=id=0;
		for(int i=0;i<10;i++) cin>>c[i],sum+=c[i];
		int lim=min(sum,6);
		while(id<lim){
			for(int i=0;i<10 && id<lim;i++){
				if(c[i]){
					c[i]--;
					p[++id]=i;
				}
			}
		}
		sort(p+1,p+id+1);
		int nw=0,s=0;
		for(int i=0;i<10;i++){
			s=(s*ksm(10,c[i])%mod+(ksm(10,c[i])+mod-1)%mod*ksm(9,mod-2)%mod)%mod;
		}
		s=s*ksm(10,id)%mod;
		bool fl=0;
		do{
			int tot=0;
			for(int i=1;i<=id;i++) tot=(tot*10%mod+p[i])%mod;
			if((s+tot)%mod==0){
				cout<<10+id<<'\n';
				for(int i=0;i<10;i++) cout<<c[i]<<" "<<i<<'\n';
				for(int i=1;i<=id;i++) cout<<1<<" "<<p[i]<<'\n';
				fl=1;
				break;
			}
		}while(next_permutation(p+1,p+id+1));
		if(!fl) puts("-1");
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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:

12
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
1 1
1 4
14
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
1 1
1 1
1 6
1 9
-1

result:

ok T=3

Test #2:

score: -100
Time Limit Exceeded

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 1
0 0 1 0 0 0 0 1 0 0
0 1 1 1 1 1 1 1 0 1
1 0 0 0 0 1 0 0 0 1
0 0 0 0 1 0 1...

output:

15
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
1 3
1 5
1 6
1 7
1 9
15
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
1 0
1 4
1 1
1 8
1 6
16
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
1 0
1 1
1 2
1 3
1 9
1 7
16
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
1 1
1 2
1 5
1 6
1 7
1 8
14
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0...

result: