제출 #743952

#제출 시각아이디문제언어결과실행 시간메모리
743952drdilyorArranging Shoes (IOI19_shoes)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h>
#ifdef ONPC
    #include "t_debug.cpp"
#else
    #define debug(...) 42
#endif
using namespace std;
//namespace pbds = __gnu_pbds;
using ll = long long;
const int inf = 1e9;
const ll infl = 1e18;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; }
template<typename Cont> int sz(const Cont& cont) { return int(cont.size()); }
const string fileio = "";
constexpr int tests = 1, nmax = 2e5, nlog = __lg(nmax), mod = 1e9+7;

long long count_swaps(std::vector<int> s) {
    int n = s.size();
    vector<int> pr(2*n,-1);
    for (int i = 0; i < n; i++) {
        if (~pr[i]) continue;
        for (int j = i+1; j < n; j++) {
            if (s[i] == s[j]) {
                pr[i] = j;
                pr[j] = i;
                break;
            }
        }
        assert(~pr[i]);
    }
    ll res = 0;
    for (int i = 0; i < n; i++) {
        if (pr[i] < i) continue;
        int cnt=  0;
        for (int j = i+1; j <= pr[i]-1; j++) {
            if (i < pr[j] && pr[j] < pr[i]) continue;
            cnt++;
        }
        res += cnt;
    }
    return res;
}
#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...