제출 #207308

#제출 시각아이디문제언어결과실행 시간메모리
207308balbitArranging Shoes (IOI19_shoes)C++14
50 / 100
1088 ms12024 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define SZ(x) (int)((x).size())
#define ALL(x) x.begin(),x.end()

#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<": "<<#__VA_ARGS__<<" = ", _do(__VA_ARGS__)
template<typename T> void _do(T &&x) {cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S&&...y) {cerr<<x<<", "; _do(y...);}
#define IOS()
#else
#define IOS() ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define bug(...)
#endif // BALBIT

const int maxn = 3e5;

vector<int> tp[maxn];

ll count_swaps(vector<int> s) {
    int n = s.size()/2;
    ll re = 0;
    for (int i = 0; i<n*2; i++) {
        int x = abs(s[i]);
        int sgn = s[i] / x;
        if (SZ(tp[x]) && tp[x].back() != sgn) {
            int npass = SZ(tp[x]);
            for (int j = i; j>=0; --j) {
                if (abs(s[j-1]) == x) {
                    npass--;
                }
                if (npass == 0){
                    if (sgn == -1) swap(s[j], s[j-1]), ++re;
                    break;
                }
                swap(s[j], s[j-1]); ++re;
            }

            tp[x].pop_back();
        }else{
            tp[x].pb(sgn);
        }
        bug(i,re);
    }
//    for (int i = 0; i<n*2; i++) {
//        cerr<<s[i]<<' ';
//    }
//    cerr<<endl;
    return re;
}

#ifdef BALBIT
signed main(){
    IOS();
    int n; cin>>n;
    vector<int> x(n*2);
    for (int i = 0; i<n*2; i++) cin>>x[i];
    cout<<count_swaps(x)<<endl;
}
#endif
#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...