Submission #590993

#TimeUsernameProblemLanguageResultExecution timeMemory
590993almothana05Arranging Shoes (IOI19_shoes)C++14
50 / 100
1084 ms25672 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; map<int , vector<int> >num; vector<pair<int , int> >erg; int vis[200000] , pref[200000]; long long count_swaps(vector<int> s) { long long menge = s.size() , be , en , re = 0; for(int i = menge - 1 ; i >= 0 ; i--){ num[s[i]].push_back(i); } for(int i = 0 ; i < menge ; i++){ if(vis[i] == 1){ continue; } be = i; en = num[s[i] * -1][num[s[i] * -1].size() - 1]; num[s[i] * -1].pop_back(); num[s[i]].pop_back(); if(be > en){ swap(be , en); } for(int j = be ; j <= en ; j++){ pref[j]++; } vis[be] = 1; vis[en] = 1; be += pref[be]; en += pref[en]; if(s[i] > 0){ re++; } re += (en - be - 1); } return re; }
#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...