QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#59988 | #1845. Permute | CharlieVinnie | WA | 273ms | 3660kb | C++17 | 2.6kb | 2022-11-02 11:49:28 | 2022-11-02 11:49:32 |
Judging History
answer
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Rev(i,a,b) for(int i=a;i>=b;i--)
#define Fin(file) freopen(file,"r",stdin)
#define Fout(file) freopen(file,"w",stdout)
using namespace std;
const int N=0; typedef long long ll;
const int A[6]={1,3,2,6,4,5};
int calc(int x,int c){
int res=0; For(i,0,c%6-1) res+=A[i];
return res*x%7;
}
void print(vector< pair<int,int> > ans){
cout<<ans.size()<<'\n';
for(auto pr:ans) cout<<pr.second<<' '<<pr.first<<'\n';
}
void solve(){
vector<int> a(10); For(i,0,9) cin>>a[i];
vector<int> cnt(7); For(i,0,9) cnt[i%7]+=a[i];
vector<int> lis; For(i,0,6) if(cnt[i]) lis.push_back(i);
vector<int> tmp(7); vector< pair<int,int> > ans;
if(lis.size()>=4u){
For(i,0,3) tmp[lis[i]]=1;
}
else if(lis.size()==3u){
int c2=0; For(i,0,2) if(cnt[lis[i]]>=2) c2++;
if(c2>=2){
For(i,0,2) if(c2&&cnt[lis[i]]>=2) { c2--; tmp[lis[i]]=2; } else tmp[lis[i]]=1;
}
else{
int c4=-1; For(i,0,2) if(cnt[lis[i]]>=4) { c4=i; break; }
if(c4!=-1){
For(i,0,2) if(i==c4) tmp[lis[i]]=4; else tmp[lis[i]]=1;
}
else{
tmp=cnt;
}
}
}
else if(lis.size()==2u){
if(cnt[lis[0]]>=3&&cnt[lis[1]]>=2){
tmp[lis[0]]=3; tmp[lis[1]]=2;
}
else if(cnt[lis[0]]>=2&&cnt[lis[1]]>=3){
tmp[lis[0]]=2; tmp[lis[1]]=3;
}
else{
tmp=cnt;
}
}
else{
int u=lis[0];
if(calc(u,cnt[u])==0){
For(i,0,9) if(i%7==u) ans.emplace_back(i,a[i]);
print(ans);
}
else{
cout<<"-1\n";
}
return;
}
int cur=0; vector<int> cp;
For(i,0,9){
if(a[i]>=tmp[i%7]) { ans.emplace_back(i,a[i]-tmp[i%7]); cur=(cur*A[(a[i]-tmp[i%7])%7]+calc(i,a[i]-tmp[i%7]))%7; while(tmp[i%7]--){cp.push_back(i);} tmp[i%7]=0; }
else For(_,1,a[i]) { tmp[i%7]--; cp.push_back(i); }
}
int sz=cp.size(),ok=0;
do{
int res=cur*A[sz]%7;
For(i,0,sz-1) res=(res+cp[i]*A[i])%7;
if(res==0){
ok=1; Rev(i,sz-1,0) ans.emplace_back(cp[i],1);
break;
}
}while(next_permutation(cp.begin(),cp.end()));
if(ok) print(ans);
else cout<<"-1\n";
}
signed main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int T; cin>>T; while(T--) solve();
cerr<<"Time = "<<clock()<<" ms"<<endl;
return 0;
}
// START TYPING IF YOU DON'T KNOW WHAT TO DO
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3644kb
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:
12 0 0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 1 1 4 13 0 0 0 1 0 3 0 4 0 5 0 6 0 7 0 8 0 9 1 9 1 6 1 1 1 1 -1
result:
ok T=3
Test #2:
score: 0
Accepted
time: 221ms
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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um mod 7 = 4 in test 121