Submission #143777

#TimeUsernameProblemLanguageResultExecution timeMemory
143777jwvg0425Arranging Shoes (IOI19_shoes)C++17
45 / 100
119 ms20856 KiB
#include "shoes.h" #include <set> std::set<int> minus[100005]; std::set<int> plus[100005]; long long count_swaps(std::vector<int> s) { std::vector<bool> used(s.size(), false); long long ans = 0; long long useCount = 0; for (int i = 0; i < s.size(); i++) { if (s[i] > 0) plus[s[i]].insert(i); else minus[-s[i]].insert(i); } for (int i = 0; i < s.size(); i++) { if (used[i]) { useCount--; continue; } if (s[i] > 0) { int near = *minus[s[i]].lower_bound(i); minus[s[i]].erase(near); used[near] = true; ans += near - i - useCount; } else { int near = *plus[-s[i]].lower_bound(i); plus[-s[i]].erase(near); used[near] = true; ans += near - i - 1 - useCount; } useCount++; } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:13:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.size(); i++)
                     ~~^~~~~~~~~~
shoes.cpp:21:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.size(); i++)
                     ~~^~~~~~~~~~
#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...