제출 #240838

#제출 시각아이디문제언어결과실행 시간메모리
240838RayaBurong25_1Arranging Shoes (IOI19_shoes)C++17
10 / 100
5 ms768 KiB
#include "shoes.h" #include <map> #include <vector> #include <algorithm> #include <set> int abs(int a) { return (a < 0)?-a:a; } long long count_swaps(std::vector<int> s) { int i, sz; long long cnt = 0; std::map<int, std::vector<int> > pos; for (i = 0; i < s.size(); i++) { sz = abs(s[i]); if (pos.find(sz) == pos.end()) pos[sz] = std::vector<int>(); pos[sz].push_back(i); } int nxt; std::vector<int> moved; int ismoved[100005] = {0}; for (i = 0; i < s.size(); i++) { sz = abs(s[i]); if (ismoved[i]) continue; // printf("%d ", sz); nxt = std::upper_bound(pos[sz].begin(), pos[sz].end(), i) - pos[sz].begin(); if (nxt == pos[sz].size()) continue; while ((long long) s[pos[sz][nxt]]*s[i] > 0) nxt++; // printf("%d ", pos[sz][nxt]); cnt += (pos[sz][nxt] - i - 1) - (std::upper_bound(moved.begin(), moved.end(), pos[sz][nxt]) - std::upper_bound(moved.begin(), moved.end(), i)); // printf("%d ", (s[i] > 0)); cnt += (s[i] > 0); moved.push_back(pos[sz][nxt]); ismoved[pos[sz][nxt]] = 1; std::sort(moved.begin(), moved.end()); // printf("%lld\n", cnt); } return cnt; }

컴파일 시 표준 에러 (stderr) 메시지

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