QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#59944#1845. PermuteAFewSunsWA 126ms3660kbC++4.4kb2022-11-02 10:01:382022-11-02 10:01:39

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:01:39]
  • 评测
  • 测评结果:WA
  • 用时:126ms
  • 内存:3660kb
  • [2022-11-02 10:01:38]
  • 提交

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;
ll t,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;
	}
}
int main(){
	t=read();
	while(t--){
		ll div=0;
		fr(i,0,9){
			a[i]=read();
			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{
				writeln(1);
				pf("%lld %lld\n",a[id[1]],id[1]);
			}
			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++;
			}
			writeln(tot+4);
			pfr(i,div,1) if(a[id[i]]) pf("%lld %lld\n",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) pf("%lld %lld\n",1ll,res[i]);
			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++;
			}
			writeln(tot+7);
			pfr(i,div,1) if(a[id[i]]) pf("%lld %lld\n",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) pf("%lld %lld\n",1ll,res[i]);
			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++;
			}
			writeln(tot+5);
			pfr(i,div,1) if(a[id[i]]) pf("%lld %lld\n",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) pf("%lld %lld\n",1ll,res[i]);
			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++;
			}
			writeln(tot+5);
			pfr(i,div,1) if(a[id[i]]) pf("%lld %lld\n",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) pf("%lld %lld\n",1ll,res[i]);
			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{
			writeln(cnt);
			fr(i,1,cnt) pf("%lld %lld\n",1ll,res[i]);
		}
	}
}
/*
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: 3636kb

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: -100
Wrong Answer
time: 126ms
memory: 3660kb

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

result:

wrong answer Participant output c[i]!=input c[i] in test 10