Submission #240864

#TimeUsernameProblemLanguageResultExecution timeMemory
240864RayaBurong25_1Arranging Shoes (IOI19_shoes)C++17
85 / 100
1099 ms147428 KiB
#include "shoes.h" #include <map> #include <vector> #include <algorithm> #include <queue> #include <cassert> int abs(int a) { return (a < 0)?-a:a; } long long count_swaps(std::vector<int> s) { int i, sz, norp; long long cnt = 0; std::map<int, std::queue<int> > pos[2]; for (i = 0; i < s.size(); i++) { sz = abs(s[i]); norp = (s[i] > 0); if (pos[norp].find(sz) == pos[norp].end()) pos[norp][sz] = std::queue<int>(); pos[norp][sz].push(i); } int nxt; std::vector<int> moved; int ismoved[200005] = {0}; for (i = 0; i < s.size(); i++) { sz = abs(s[i]); norp = (s[i] > 0); if (ismoved[i]) continue; // printf("%d ", sz); if (pos[!norp][sz].size() == 0) continue; // while ((long long) ismoved[pos[!norp][sz][nxt]]) // nxt++; // printf("%d ", pos[sz][nxt]); cnt += (pos[!norp][sz].front() - i - 1) - (std::upper_bound(moved.begin(), moved.end(), pos[!norp][sz].front()) - std::upper_bound(moved.begin(), moved.end(), i)); // printf("%d ", (s[i] > 0)); cnt += (s[i] > 0); moved.insert(std::upper_bound(moved.begin(), moved.end(), pos[!norp][sz].front()), pos[!norp][sz].front()); ismoved[pos[!norp][sz].front()] = 1; pos[!norp][sz].pop(); pos[norp][sz].pop(); // printf("%lld\n", cnt); } return cnt; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:17:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 0; i < s.size(); i++)
              ~~^~~~~~~~~~
shoes.cpp:28:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 0; i < s.size(); i++)
              ~~^~~~~~~~~~
shoes.cpp:25:6: warning: unused variable 'nxt' [-Wunused-variable]
  int nxt;
      ^~~
#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...