QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#571414#3117. Cyclic antimonotonic permutationslime100 ✓201ms7540kbC++14934b2024-09-17 22:47:312024-09-17 22:47:32

Judging History

This is the latest submission verdict.

  • [2024-09-17 22:47:32]
  • Judged
  • Verdict: 100
  • Time: 201ms
  • Memory: 7540kb
  • [2024-09-17 22:47:31]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

#define _ std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define dgb(x) cout << #x << " = " << x << endl;
#define ll long long
#define uint unsigned int
#define MP make_pair
#define PB push_back
#define pii pair<int, int>

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;

int main (void) {_
    int n;
    vector<int> permutacao;

    while (cin >> n && n) {
        permutacao = vector<int>(n+1);

        permutacao[1] = 1;
        iota(permutacao.begin()+2, permutacao.end(), 2);

        for (int i = 2; i <= n; i++) {
            if (i & 1) swap(permutacao[i], permutacao[i-2]);
            else swap(permutacao[i], permutacao[i-1]);
        }

        cout << permutacao[1] ;
        for (int i = 2; i <= n; i++) cout << ' ' << permutacao[i];
        cout << endl;

    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 100
Accepted
time: 201ms
memory: 7540kb

input:

3
4
5
6
7
8
9
10
11
12
686
44
292
17
1000000
95211
8763
21
28
31
46429
25
215
18
55368
3059
577
27
40
36
48
4736
349
34
983
19
821
7172
39
16
22
665382
33
386
20
32
999999
26
9690
13
42
47
6926
5027
91530
38
803655
15
723171
35
50
45
29
7540
576450
46
24
393
37
4362
55782
23
14
41
49
43
935
52567
30...

output:

3 1 2
3 1 4 2
3 1 5 2 4
3 1 5 2 6 4
3 1 5 2 7 4 6
3 1 5 2 7 4 8 6
3 1 5 2 7 4 9 6 8
3 1 5 2 7 4 9 6 10 8
3 1 5 2 7 4 9 6 11 8 10
3 1 5 2 7 4 9 6 11 8 12 10
3 1 5 2 7 4 9 6 11 8 13 10 15 12 17 14 19 16 21 18 23 20 25 22 27 24 29 26 31 28 33 30 35 32 37 34 39 36 41 38 43 40 45 42 47 44 49 46 51 48 53 ...

result:

ok correct (80 test cases)