QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#842381#1845. PermutehicgnliawWA 96ms3896kbC++143.3kb2025-01-04 12:10:542025-01-04 12:10:54

Judging History

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

  • [2025-01-04 12:10:54]
  • 评测
  • 测评结果:WA
  • 用时:96ms
  • 内存:3896kb
  • [2025-01-04 12:10:54]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int rc[6] = {1,3,2,6,4,5};
int T,rcnt[10],cnt[7],kd,sum,apn[7],spn[7],sc,akd;
int f(int p){
	return rc[p%6];
}
void getv(int x,int c = -1){
	if(c>=0){
		int dl = min(c,rcnt[x]);
//		printf("%d %d!\n",c,dl);
		printf("%d %d\n",dl,x);
		c-=dl;
		rcnt[x]-=dl;
		x+=7;
		printf("%d %d\n",c,(x<10?x:0));
		if(x<10)rcnt[x]-=c;
		return;
	}
	if(rcnt[x])rcnt[x]--,spn[sc++] = x;
	else rcnt[x+7]--,spn[sc++] = x+7;
	if(!rcnt[spn[sc-1]])akd--;
}
int pt(){
	int r = 0;
	for(int i = 0;i<10;i++){
		if(rcnt[i]){
			printf("%d %d\n",rcnt[i],i);
			r+=(f(sum)-f(sum-rcnt[i]))*i;
			sum-=rcnt[i];
		}
	}
	return (r*4%7+7)%7;
}
void bl(){
	sort(spn,spn+sc);
	printf("%d\n",sc+akd);
	int nr,r = pt();
//	printf("%d\n",r);
	do{
		nr = 0;
		for(int i = 0;i<sc;i++)nr = (nr*3+spn[i])%7;
		if((nr+r)%7==0)break;
	}while(next_permutation(spn,spn+sc));
	if((nr+r)%7)exit(int('?'));
	for(int i = 0;i<sc;i++)printf("1 %d\n",spn[i]);
}
int main(){
	scanf("%d",&T);
	while(T--){
		memset(cnt,0,sizeof(cnt));
		sum = akd = 0;
		for(int i = 0;i<10;i++){
			scanf("%d",&rcnt[i]);
			if(rcnt[i])akd++;
			cnt[i%7]+=rcnt[i];
			sum+=rcnt[i];
		}
		kd = 0;
		for(int i = 0;i<7;i++)if(cnt[i])apn[kd++] = i;
		sc = 0;
		if(kd>=4){
			for(int i = 0;i<4;i++)getv(apn[i]);
			bl();
		}else if(kd==3){
			int co = 0;
			for(int i:{0,1,2})if(cnt[apn[i]]==1)co++;
			if(co<=1){
				for(int i:{1,2})if(cnt[apn[i]]==1)swap(apn[i],apn[0]);
				getv(apn[0]);
				for(int i:{1,2}){
					for(int ct:{1,2})getv(apn[i]);
				}
				bl();
			}else{
//				printf("?");
//				for(int i = 0;i<10;i++)printf("%d ",rcnt[i]);
//				printf("\n");
				for(int i:{0,1})if(cnt[apn[i]]!=1)swap(apn[i],apn[2]);
				int r = (f(sum)-1)*apn[2]*4%7,cr = min(sum,12),d[2] = {apn[0]-apn[2],apn[1]-apn[2]};
				bool fg = 0;
				for(int i = 0;i<cr;i++){
					for(int j = 0;j<cr;j++){
						if(i==j)continue;
						if(((r+f(i)*d[0]+f(j)*d[1])%7+7)%7==0){
							printf("10\n");
							getv(apn[2],sum-max(i,j)-1);
							if(i>j)getv(apn[0],1);
							else getv(apn[1],1);
							getv(apn[2],abs(i-j)-1);
							if(i<j)getv(apn[0],1);
							else getv(apn[1],1);
							getv(apn[2],min(i,j));
							fg = 1;
							break;
						}
					}
					if(fg)break;
				}
				if(!fg)printf("-1\n"); 
			}
		}else if(kd==2){
			if(sum<=5){
				for(int i = 0;i<10;i++){
					while(rcnt[i]--)spn[sc++] = i;
				}
				int nr;
				do{
					nr = 0;
					for(int i = 0;i<sc;i++)nr = (nr*3+spn[i])%7;
					if(!nr)break;
				}while(next_permutation(spn,spn+sc));
				if(nr){
					printf("-1\n");
				}else{
					printf("%d\n",sum);
					for(int i = 0;i<sum;i++)printf("1 %d\n",spn[i]);
				}
			}else{
				if(cnt[apn[0]]>cnt[apn[1]])swap(apn[0],apn[1]);
				if(cnt[apn[0]]>1){
//					printf("!");
					for(int ct:{0,1})getv(apn[0]);
					for(int ct:{0,1,2})getv(apn[1]);
					bl();
				}else{
					int r = (f(sum)-1)*4*apn[1]%7;
					bool fg = 0;
					for(int i = 0;i<6;i++){
						if((f(i)*(apn[0]-apn[1]+7)+r)%7==0){
							printf("6\n");
							getv(apn[1],sum-i-1);
							getv(apn[0],1);
							getv(apn[1],i);
							fg = 1;
							break;
						}
					}
					if(!fg)printf("-1\n");
				}
			}
		}else{
			if(sum%6)printf("-1\n");
			else{
				printf("2\n");
				getv(apn[0],sum);
			}
		}
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3840kb

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
10
2 1
0 8
1 6
0 0
0 1
0 8
0 2
1 9
0 1
0 8
-1

result:

ok T=3

Test #2:

score: -100
Wrong Answer
time: 96ms
memory: 3896kb

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

result:

wrong answer Jury has the answer but participant has not