QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#59952#1845. PermuteAFewSunsWA 263ms3724kbC++2.9kb2022-11-02 10:23:022022-11-02 10:23:04

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:23:04]
  • 评测
  • 测评结果:WA
  • 用时:263ms
  • 内存:3724kb
  • [2022-11-02 10:23:02]
  • 提交

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;
mt19937 rd(time(NULL));
ll t,a[11],id[55],tot=0,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;
	}
}
int main(){
	t=read();
	while(t--){
		tot=0;
		fr(i,0,9){
			a[i]=read();
			fr(j,1,min(a[i],4ll)) id[++tot]=i;
		}
		if(tot<4){
			nd=0;
			cnt=tot;
			fr(i,1,tot) p[i]=id[i];
			pd=0;
			dfs(0);
			if(!pd) writeln(-1);
			else{
				writeln(tot);
				fr(i,1,tot) pf("%lld %lld\n",1ll,res[i]);
			}
			continue;
		}
		fr(_,1,100){
			shuffle(id+1,id+tot+1,rd);
			fr(i,1,4) a[id[i]]--;
			ll tmp=pw[4],cntt=0;
			nd=0;
			fr(i,0,9){
				if(!a[i]) continue;
				nd=(nd+b[a[i]%6]*tmp*i%7)%7;
				tmp=tmp*pw[a[i]%6]%7;
				cntt++;
			}
			pd=0;
			cnt=4;
			fr(i,1,cnt) p[i]=id[i];
			dfs(0);
			if(pd){
				writeln(cntt+4);
				pfr(i,9,0) if(a[i]) pf("%lld %lld\n",a[i],i);
				fr(i,1,cnt) pf("%lld %lld\n",1ll,res[i]);
				break;
			}
			fr(i,1,4) a[id[i]]++;
		}
		if(!pd) writeln(-1);
	}
}
/*
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

1
1 0 0 1 1 0 0 1 0 0
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 184ms
memory: 3724kb

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:

5
1 9
1 3
1 7
1 6
1 5
5
1 0
1 4
1 1
1 8
1 6
6
1 3
1 2
1 7
1 0
1 1
1 9
6
1 7
1 1
1 5
1 8
1 6
1 2
4
1 8
1 2
1 4
1 6
-1
4
1 0
1 1
1 8
1 9
5
1 6
1 3
1 0
1 4
1 2
5
1 1
1 2
1 9
1 5
1 7
-1
6
1 8
1 6
1 1
1 9
1 0
1 3
-1
8
1 9
1 6
1 5
1 1
1 2
1 3
1 7
1 4
-1
4
1 6
1 4
1 8
1 9
7
1 7
1 5
1 0
1 6
1 9
1 8
1 2
6
1 ...

result:

ok T=100000

Test #3:

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

input:

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

result:

ok T=100000

Test #5:

score: 0
Accepted
time: 260ms
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:

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

result:

ok T=100000

Test #6:

score: -100
Wrong Answer
time: 263ms
memory: 3664kb

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:

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

result:

wrong answer Jury has the answer but participant has not