QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#59981#1845. PermuteAFewSunsRE 2ms3656kbC++5.3kb2022-11-02 11:21:522022-11-02 11:21:54

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-02 11:21:54]
  • Judged
  • Verdict: RE
  • Time: 2ms
  • Memory: 3656kb
  • [2022-11-02 11:21:52]
  • Submitted

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();
	fr(qwq,1,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){
		assert(qwq!=371);
			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=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]);
			fr(i,1,7) nd=(nd*10+id[3])%7;
			pd=0;
			fr(i,1,7){
				fr(j,1,7){
					if(i==j) continue;
					nd=(nd-id[3]*pw[(i-1)%6]%7+7)%7;
					nd=(nd-id[3]*pw[(j-1)%6]%7+7)%7;
					nd=(nd+id[1]*pw[(i-1)%6]%7)%7;
					nd=(nd+id[2]*pw[(j-1)%6]%7)%7;
					if(!nd){
						if(i<j){
							prf(7-j,id[3]);
							prf(1,id[2]);
							prf(j-i-1,id[3]);
							prf(1,id[1]);
							prf(i-1,id[3]);
						}
						else{
							prf(7-i,id[3]);
							prf(1,id[1]);
							prf(i-j-1,id[3]);
							prf(1,id[2]);
							prf(j-1,id[3]);
						}
						pd=1;
						break;
					}
					nd=(nd-id[1]*pw[(i-1)%6]%7+7)%7;
					nd=(nd-id[2]*pw[(j-1)%6]%7+7)%7;
					nd=(nd+id[3]*pw[(i-1)%6]%7)%7;
					nd=(nd+id[3]*pw[(j-1)%6]%7)%7;
				}
				if(pd) break;
			}
			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();
		}
	}
}

详细

Test #1:

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

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
Dangerous Syscalls

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

result: