Submission #1224953

#TimeUsernameProblemLanguageResultExecution timeMemory
1224953im2xtremeArranging Shoes (IOI19_shoes)C++20
0 / 100
1096 ms1864 KiB
#include <iostream> #include <vector> #include <algorithm> // for std::swap #include "shoes.h" using namespace std; long long count_swaps(vector<int> S) { long long swaps = 0; int n = S.size(); for (int i = 0; i < n; ++i) { if (S[i] < 0) continue; // Skip right shoes // S[i] is a left shoe int size = S[i]; // Find matching right shoe -size int j = i + 1; while (j < n && S[j] != -size) ++j; // Move S[j] to position i+1 via adjacent swaps while (j > i + 1) { swap(S[j], S[j - 1]); swaps++; j--; } // Skip the next position (it's part of the matched pair now) i++; } 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...