Submission #144209

#TimeUsernameProblemLanguageResultExecution timeMemory
144209FelixMPArranging Shoes (IOI19_shoes)C++14
30 / 100
35 ms3452 KiB
#include "shoes.h"

using namespace std;

typedef long long int ll;

long long count_swaps(std::vector<int> s) {
	int n = s.size();
    vector<ll> open = vector<ll>(n+1, 0);
    vector<bool> openR = vector<bool>(n+1, false);
    ll copen = 0;
    ll inv = 0;
    ll stol = 0;
    ll dtol = 0;
    for(int i=0; i < n; ++i) {
        ll cs = (s[i] > 0) ? s[i] : -s[i]; 
        if(s[i] > 0) {
            if(open[cs] > 0 and !openR[cs]) {
                copen--;
                open[cs]--;
                stol += open[cs];
                dtol += copen-open[cs];
                if(open[cs] == 0) {
                    
                }
            }
            else {
                stol += open[cs];
                dtol += copen-open[cs];
                open[cs]++;
                copen++;
                if(open[cs] == 1) {
                    openR[cs] = true;
                }
            }
        }
        else {
            if(open[cs] > 0 and openR[cs]) {
                copen--;
                open[cs]--;
                stol += open[cs];
                dtol += copen-open[cs];
                inv++;
                if(open[cs] == 0) {
                    openR[cs] = false;
                }
            }
            else {
                stol += open[cs];
                dtol += copen-open[cs];
                open[cs]++;
                copen++;
            }
        }
    }
    return dtol+stol/2+inv;
}
#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...