QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#59991#1845. PermuteCharlieVinnieWA 269ms3640kbC++172.8kb2022-11-02 12:37:352022-11-02 12:37:38

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-02 12:37:38]
  • 评测
  • 测评结果:WA
  • 用时:269ms
  • 内存:3640kb
  • [2022-11-02 12:37:35]
  • 提交

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';
}
int cy;
void solve(int T){
    vector<int> a(10); For(i,0,9) cin>>a[i];
    // if(T==1&&a[0]==2) cy=1;
    // if(cy){
    //     if(T==121) { For(i,0,9) cout<<a[i]<<' ';  cout<<endl; }
    //     return;
    // }
    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){
            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%6]%7;
        For(i,0,sz-1) res=(res+cp[i]*A[i%7])%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,Ti=0; cin>>T; while(T--) solve(++Ti);
    cerr<<"Time = "<<clock()<<" ms"<<endl;
    return 0;
}

// START TYPING IF YOU DON'T KNOW WHAT TO DO

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 252ms
memory: 3572kb

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:

12
0 1
0 3
0 4
0 5
1 6
0 7
0 8
0 9
1 9
1 5
1 7
1 3
14
0 0
0 1
0 2
0 3
0 4
0 5
0 6
0 7
1 8
0 9
1 6
1 4
1 0
1 1
14
0 0
0 1
0 2
0 3
0 4
0 5
0 6
1 7
0 8
1 9
1 0
1 3
1 2
1 1
13
0 1
0 2
0 3
0 4
0 5
1 6
0 7
1 8
0 9
1 7
1 5
1 1
1 2
13
0 0
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
1 6
1 4
1 8
1 2
-1
12
0 0
0 3
0 4
0 5...

result:

ok T=100000

Test #3:

score: 0
Accepted
time: 256ms
memory: 3628kb

input:

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

output:

14
1 0
0 1
1 2
0 3
0 4
1 5
1 6
0 7
2 8
0 9
1 2
1 0
1 3
1 1
13
0 0
1 1
0 3
1 4
2 5
1 6
1 7
2 8
0 9
1 9
1 1
1 0
1 3
14
1 0
1 1
1 2
0 3
0 4
2 5
1 6
1 7
2 8
2 9
1 3
1 2
1 1
1 0
14
0 0
0 1
0 2
1 3
0 4
1 5
0 6
1 7
2 8
0 9
1 5
1 0
1 3
1 1
13
0 0
1 2
1 3
1 4
2 5
1 6
0 7
1 8
2 9
1 2
1 8
1 3
1 0
13
0 1
1 2
1 ...

result:

ok T=100000

Test #4:

score: -100
Wrong Answer
time: 269ms
memory: 3632kb

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:

14
0 0
2 1
2 2
1 3
3 4
0 5
2 6
1 7
3 8
2 9
1 3
1 1
1 2
1 0
14
2 0
0 1
1 2
0 3
0 4
2 5
1 6
0 7
0 8
1 9
1 1
1 5
1 2
1 0
13
2 0
1 1
1 3
0 4
2 5
0 6
1 7
3 8
0 9
1 9
1 1
1 0
1 3
12
0 1
2 3
1 4
1 5
0 6
2 7
0 8
1 9
1 3
1 9
1 7
1 1
14
1 0
1 1
1 2
2 3
3 4
3 5
1 6
0 7
3 8
0 9
1 2
1 3
1 1
1 0
13
0 0
2 1
1 3
0 ...

result:

wrong answer Jury has the answer but participant has not