Submission #1187080

#TimeUsernameProblemLanguageResultExecution timeMemory
1187080eri16Arranging Shoes (IOI19_shoes)C++20
0 / 100
1096 ms1860 KiB
#include "shoes.h" #include <iostream> #include <vector> #include <cmath> using namespace std; long long count_swaps(vector<int> S) { long long swaps = 0; int n = S.size(); for (int i = 0; i < n; ) { if (S[i] < 0) { // Skip right shoes — can't start a pair ++i; continue; } int size = S[i]; // Find matching right shoe int j = i + 1; while (j < n && S[j] != -size) { ++j; } // Move the right shoe leftward to i + 1 while (j > i + 1) { swap(S[j], S[j - 1]); --j; ++swaps; } // Now valid pair at i, i+1 i += 2; } return swaps; }
#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...