제출 #1153219

#제출 시각아이디문제언어결과실행 시간메모리
1153219browntoadArranging Shoes (IOI19_shoes)C++20
50 / 100
1095 ms1864 KiB
#include <bits/stdc++.h>
#include "shoes.h"
using namespace std;
#define ll long long
// #define int ll
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n)-1; i >= 0; i--)
#define RREP1(i, n) for (int i = (n); i >= 1; i--)
#define REP1(i, n) FOR(i, 1, n+1)
#define pii pair<int, int>
#define ppi pair<pii, int>
#define pip pair<int, pii>
#define f first
#define s second
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define endl '\n'
#define IOS() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

const ll maxn = 2e5+5;
const ll inf = 1e9;
const ll mod = 998244353;

ll pw(ll x, ll p, ll m){
    ll ret = 1;
    while(p > 0){
        if (p & 1){
            ret *= x;
            ret %= m;
        }
        x *= x;
        x %= m;
        p >>= 1;
    }
    return ret;
}
ll inv(ll x, ll m){
    return pw(x, m-2, m);
}

ll count_swaps(vector<int> v){
    int n = SZ(v);

    vector<bool> occ(n);

    ll ans = 0;
    REP(i, n){
        if (occ[i]) continue;

        int pos = 0, gl = -v[i], cnt = 0;
        FOR(j, i+1, n){
            if (occ[j]) continue;
            cnt++;
            if (v[j] == gl){
                pos = j;
                break;
            }
        }

        ans += cnt-(v[i] < 0);
        occ[pos] = 1;
    }
    return ans;
}
/*
signed main(){
    cout<<count_swaps({1, 2, -1, 2, 1, -2, -2, -1})<<endl;
}
*/
/*
4 4
1 2
2 3
3 1
1 4
*/




#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...