QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#94188#6131. Tournamentinstallb#WA 2ms3584kbC++141.5kb2023-04-05 14:54:312023-04-05 14:54:35

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-05 14:54:35]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3584kb
  • [2023-04-05 14:54:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define M 1005
using pii = pair<int,int>;
vector<pii> A[M];
int n,K,m;
void solve(){
    m = 0;
    int t = 0,p = n;
    while(p+1&1){
        if(m==0){
            for(int i=1;i<=n;i+=2)
                A[m].push_back(pii(i,i+1));
            m++;
            t = 1;
            p>>=1;
        }else{
            int lastm = m;
            for(int k=0;k<lastm;k++){
                for(int i=0;i<A[k].size();i+=t+t){
                    for(int j=0;j<t;j++){
                        auto [x,y] = A[k][i+j];
                        auto [a,b] = A[k][i+j+t];
                        A[m].push_back(pii(x,a));
                        A[m].push_back(pii(y,b));

                        A[m+1].push_back(pii(x,b));
                        A[m+1].push_back(pii(y,a));
                    }
                }
                m+=2;
            }
            p>>=1;
        }
    }
    if(m<K)puts("Impossible");
    else{
        for(int i=0;i<K;i++){
            static int pos[M];
            for(auto [x,y]:A[i])pos[x] = y,pos[y] = x;
            for(int j=1;j<=n;j++){
                printf("%d",pos[j]);
                if(j<n)putchar(' ');
            }
            puts("");
            // if(i<K-1)puts("");
        }
    }
    for(int i=0;i<m;i++)A[i].clear();
}
int main(){
    int Cas;cin>>Cas;
    while(Cas--){
        scanf("%d%d",&n,&K);
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
3 1
4 3

output:

Impossible
2 1 4 3
3 4 1 2
4 3 2 1

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3552kb

input:

100
1 4
2 1
2 2
2 3
3 6
4 2
4 3
4 4
4 5
5 4
6 1
6 2
6 4
7 1
8 3
8 7
8 8
8 14
9 4
10 1
10 2
10 3
12 2
12 3
12 4
12 8
13 2
14 1
14 2
14 4
15 4
16 9
16 15
16 16
16 28
17 6
18 1
18 2
18 4
19 5
20 1
20 3
20 4
20 6
21 1
22 1
22 2
22 3
23 4
24 5
24 7
24 8
24 15
25 3
26 1
26 2
26 3
27 5
28 1
28 3
28 4
28 6
...

output:

Impossible
2 1
Impossible
Impossible
Impossible
2 1 4 3
3 4 1 2
2 1 4 3
3 4 1 2
4 3 2 1
Impossible
Impossible
Impossible
2 1 4 3 6 5
Impossible
Impossible
Impossible
2 1 4 3 6 5 8 7
3 4 1 2 7 8 5 6
4 3 2 1 8 7 6 5
2 1 4 3 6 5 8 7
3 4 1 2 7 8 5 6
4 3 2 1 8 7 6 5
3 4 1 2 7 8 5 6
4 3 2 1 8 7 6 5
2 1 4 ...

result:

wrong answer 24th lines differ - expected: '5 6 7 8 1 2 3 4', found: '3 4 1 2 7 8 5 6'