QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#828550#1845. PermuteKazemaruTL 870ms25168kbC++14940b2024-12-23 18:01:462024-12-23 18:01:46

Judging History

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

  • [2024-12-23 18:01:46]
  • 评测
  • 测评结果:TL
  • 用时:870ms
  • 内存:25168kb
  • [2024-12-23 18:01:46]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,j,k) for(int i=j;i<=k;++i)
#define g(i,j,k) for(int i=j;i>=k;--i)
int n,m,s,l;
const int N=3e6;
vector<int>c(7);
map<vector<int>,int>f[7];
int a[N],b[N],p[N],q[N];
int dfs(int n,int k){
	if(!n)return!k+1;
	if(f[k][c]==1)return 1;
	f(i,0,6)if(c[i]){
		--c[i];
		int p=dfs(n-1,(k-i+7)*5%7);
		++c[i];
		if(p>1)return b[n]=i,f[k][c]=2;
	}
	return f[k][c]=1;
}
inline void doing(){
	f(i,0,6)b[i]=0;n=m=s=0;
	f(i,0,9)cin>>a[i],b[i%7]+=a[i];
	f(i,0,6)s+=!!b[i];s=s>3?6:9;
	f(i,0,6)for(m+=c[i]=b[i]%6;c[i]+6<=min(s,b[i]);c[i]+=6)m+=6;
	if(dfs(m,0)<2)return puts("-1"),void();
	f(i,1,m)f(c,0,9)if(c%7==b[i]&&a[c]){
		p[++n]=1;--a[q[n]=c];break;
	}
	f(i,0,6)f(c,0,9)if(c%7==i&&a[c])p[++n]=a[c],q[n]=c;
	printf("%lld\n",n);
	f(i,1,n)printf("%lld %lld\n",p[i],q[i]);
}
signed main(){
	int t;
	cin>>t;
	while(t--)doing();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9880kb

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:

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

result:

ok T=100000

Test #4:

score: 0
Accepted
time: 870ms
memory: 25168kb

input:

100000
1 3 3 2 3 0 2 1 3 2
3 1 2 0 0 3 1 0 0 1
3 2 0 2 0 2 0 1 3 1
0 1 0 3 1 1 0 3 0 2
2 2 2 3 3 3 1 0 3 0
0 3 0 2 0 3 2 0 2 3
3 0 1 1 3 3 2 1 3 1
1 2 3 0 1 2 2 0 2 3
3 1 0 3 2 0 2 3 1 0
2 1 2 3 0 2 2 3 1 2
3 3 0 3 0 0 1 1 1 1
1 3 1 0 2 1 0 3 3 3
3 0 0 3 3 2 3 3 2 1
3 3 3 1 0 2 3 0 2 3
3 3 1 3 3 2 3...

output:

20
1 4
1 4
1 4
1 6
1 6
1 3
1 3
1 2
1 2
1 2
1 9
1 9
1 1
1 1
1 1
1 8
1 8
1 8
1 0
1 7
11
1 6
1 5
1 5
1 5
1 2
1 2
1 9
1 1
1 0
1 0
1 0
14
1 3
1 3
1 5
1 5
1 9
1 1
1 1
1 8
1 8
1 8
1 0
1 0
1 0
1 7
11
1 3
1 4
1 3
1 5
1 3
1 9
1 9
1 1
1 7
1 7
1 7
19
1 5
1 6
1 5
1 5
1 4
1 4
1 4
1 3
1 3
1 3
1 2
1 2
1 1
1 1
1 8
1...

result:

ok T=100000

Test #5:

score: -100
Time Limit Exceeded

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