Submission #1005164

# Submission time Handle Problem Language Result Execution time Memory
1005164 2024-06-22T08:18:14 Z GrindMachine MalnaRISC (COI21_malnarisc) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a,b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a,b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

/*

refs:
https://www.javatpoint.com/daa-comparison-network (whole sorting networks chapter)

*/

const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

vector<vector<pii>> bitonic_sort(vector<int> &a){
    if(sz(a) <= 1){
        return vector<vector<pii>>();
    }

    vector<pii> half_cleaner;
    int siz = sz(a);

    rep(i,siz/2){
        half_cleaner.pb({a[i],a[i+siz/2]});
    }
    
    vector<int> b,c;
    rep(i,siz){
        if(i < siz/2){
            b.pb(a[i]);
        }
        else{
            c.pb(a[i]);
        }
    }    

    auto resl = bitonic_sort(b);
    auto resr = bitonic_sort(c);

    if(sz(resl) < sz(resr)){
        swap(resl,resr);
    }

    rep(i,sz(resr)){
        trav(px,resr[i]){
            resl[i].pb(px);
        }
    }

    resl.insert(resl.begin(),half_cleaner);
    return resl;
}

vector<vector<pii>> sort(vector<int> &a){
    if(sz(a) <= 1){
        return vector<vector<pii>>();
    }

    vector<int> b,c;
    rep(i,sz(a)){
        if(i < sz(a)/2){
            b.pb(a[i]);
        }
        else{
            c.pb(a[i]);
        }
    }

    auto resl = sort(b);
    auto resr = sort(c);

    if(sz(resl) < sz(resr)){
        swap(resl,resr);
    }

    rep(i,sz(resr)){
        trav(px,resr[i]){
            resl[i].pb(px);
        }
    }

    reverse(all(c));
    auto bitonic = b;
    trav(x,c) bitonic.pb(x);

    auto ops = bitonic_sort(bitonic);

    trav(v,ops) resl.pb(v);
    return resl;
}

void solve(int test_case)
{
    int n; cin >> n;
    vector<int> a(n);
    iota(all(a),1);

    auto ans = sort(a);
    // trav(v,ans){
    //     trav(px,v){
    //         if(px.ff > px.ss){
    //             swap(px.ff,px.ss);
    //         }
    //     }
    // }

    // trav(v,ans){
    //     for(auto [i,j] : v){
    //         printf("{%d,%d},\n",i,j);
    //     }
    // }

    // return;

    cout << sz(ans) << endl;

    trav(v,ans){
        for(auto [i,j] : v){
            cout << "CMPSWP R" << i << " " << "R" << j << " ";
        }
        cout << endl;
    }
}

int main()
{
    fastio;

    int t = 1;
    // cin >> t;

    rep1(i, t) {
        solve(i);
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB not sorted
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB not sorted
2 Halted 0 ms 0 KB -