QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#828519 | #1845. Permute | Kazemaru | WA | 176ms | 10044kb | C++14 | 944b | 2024-12-23 17:44:39 | 2024-12-23 17:44:40 |
Judging History
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])return f[k][c];
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?7:30;
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: 2ms
memory: 9940kb
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: 176ms
memory: 10044kb
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 5 1 3 1 6 1 9 1 7 5 1 4 1 1 1 8 1 6 1 0 6 1 3 1 1 1 2 1 9 1 0 1 7 6 1 6 1 5 1 1 1 2 1 8 1 7 4 1 8 1 4 1 2 1 6 -1 4 1 1 1 8 1 9 1 0 5 1 0 1 3 1 4 1 2 1 6 5 1 1 1 2 1 9 1 5 1 7 -1 6 1 9 1 6 1 1 1 8 1 0 1 3 -1 8 1 1 1 3 1 6 1 5 1 2 1 9 1 7 1 4 -1 4 1 8 1 9 1 4 1 6 7 1 8 1 2 1 9 1 5 1 0 1 7 1 6 6 1 ...
result:
wrong answer Participant output sum mod 7 = 5 in test 5