Submission #520533

# Submission time Handle Problem Language Result Execution time Memory
520533 2022-01-30T08:37:45 Z kartel MalnaRISC (COI21_malnarisc) C++14
67.5706 / 100
1 ms 332 KB
#include <bits/stdc++.h>
//#include<ext/rope>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC target("avx2")


#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#define F first
#define S second
#define pb push_back
#define sz(x) int(x.size())
#define el '\n'
#define all(x) x.begin(), x.end()

using namespace std;
//using namespace __gnu_pbds;
//using  namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef short int si;
typedef unsigned long long ull;
//typedef tree <ll, null_type, less <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;

vector <pair <int, int> > ans[200];
int mx_d = 0;
int D[100];

void solve(int l, int r, int d) {
    if (l == r){
        return;
    }

    int md = (l + r) >> 1;
    for (int i = l, j = md + 1; i <= md; i++, j++) {
        if (j <= r) {
            ans[d].pb({i, j});
        }
    }
    solve(l, md, d + 1);
    solve(md + 1, r, d + 1);
}

void solve1(int l, int r, int d, bool need_ret) {
    if (l == r){
        return;
    }

    int md = (l + r) >> 1;
    if (!need_ret) {
        solve1(l, md, d + 1, 0);
        solve1(md + 1, r, d + 1, 0);
    }

    for (int i = md, j = md + 1; i >= l; i--, j++) {
        if (j <= r) {
            ans[d].pb({i, j});
        }
    }
}

void swp(int &a, int &b) {
    if (a > b) {
        swap(a, b);
    }
}

int n;
void check_ans(vector <vector <pair <int, int> > > ans) {
    vector <int> a(n);
    iota(all(a), 0);
    do {
        vector <int> b = a;
        for (auto x : ans) {
            for (auto [i, j] : x) {
                swp(b[i - 1], b[j - 1]);
            }
        }
        int i = 0;
        while (i < n && b[i] == i) {
            i++;
        }
        if (i < n) {
            cout << "BAD: ";
            for (auto x : a) {
                cout << x + 1 << " ";
            }
            cout << el;
        }
    } while (next_permutation(all(a)));
}

int main()
{
//    cerr.precision(7);
//    cerr << fixed;
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    in("23.in");
//    in("input.txt");
//    out("output.txt");
//    clock_t start = clock();

    cin >> n;

    for (int i = 0; i < n; i++) {
        D[i] = -1;
    }

    vector <vector <pair <int, int> > > cur_ans;
    solve1(1, n, 0, 0);
    for (int d = 149; d >= 0; d--) {
        if (sz(ans[d])) {
            cur_ans.pb(ans[d]);
        }
        if (n <= 53 && sz(ans[d + 1])) {
            cur_ans.pb(ans[d + 1]);
        }
    }
    for (int i = 0; i < 150; i++) {
        ans[i].clear();
    }
    if (n <= 53) {
        solve(1, n, 0);
        for (int i = 0; i < 150; i++) {
            if (sz(ans[i])) {
                cur_ans.pb(ans[i]);
            }
        }
    }

    int m = sz(cur_ans);
    for (int i = 0; i < min(8, n / (n <= 53 ? 16 : 8)); i++) {
        for (int i = 0; i < m; i++) {
            cur_ans.pb(cur_ans[i]);
        }
    }

//    check_ans(cur_ans);

    cout << sz(cur_ans) << el;
    for (auto x : cur_ans) {
        for (auto [p1, p2] : x) {
            cout << "CMPSWP R" << p1 << " R" << p2 << " ";
        }
        cout << el;
    }
}

Compilation message

malnarisc.cpp: In function 'void check_ans(std::vector<std::vector<std::pair<int, int> > >)':
malnarisc.cpp:81:23: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   81 |             for (auto [i, j] : x) {
      |                       ^
malnarisc.cpp: In function 'int main()':
malnarisc.cpp:148:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  148 |         for (auto [p1, p2] : x) {
      |                   ^
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 204 KB Partially correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 204 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 332 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 332 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 332 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 332 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 332 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 332 KB Partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 332 KB Partially correct