제출 #987884

#제출 시각아이디문제언어결과실행 시간메모리
987884kachim2Arranging Shoes (IOI19_shoes)C++17
10 / 100
5 ms5260 KiB
#include "shoes.h" #include <climits> #include <vector> #include <iostream> long long count_swaps(std::vector<int> s) { std::vector<int> pos(s.size(), INT_MIN); std::vector<int> spos(s.size()); std::vector<int> rpos(s.size()); for (int i = 0; i < s.size(); i++) { spos[i] = i; } for (int i = 0; i < s.size(); i++) { rpos[i] = i; } std::vector<int> qm[100007]; std::vector<int> qp[100007]; for (int i = 0; i < s.size(); i++) { if (s[i] < 0) { if (qp[-s[i]].empty()) { qm[-s[i]].push_back(i); } else { auto x = *qp[-s[i]].rbegin(); qp[-s[i]].pop_back(); pos[i] = x; } } else { if (qm[s[i]].empty()) { qp[s[i]].push_back(i); } else { auto x = *qm[s[i]].rbegin(); qm[s[i]].pop_back(); pos[i] = x; } } } long count = 0; for (int i = 0; i < s.size(); i++) { if (pos[i] >= 0) { int wp = s[spos[i]] > 0 ? spos[pos[i]] + 1 : spos[pos[i]]; count+=spos[i]-wp; for (int j = wp; j < spos[i]; j++) { spos[rpos[j]]++; rpos[spos[j]] = j; } spos[i] = wp; rpos[wp] = i; } } /* for (auto i : spos) { std::cerr << i << ' '; } std::cerr << '\n'; for (auto i : rpos) { std::cerr << i << ' '; } std::cerr << '\n'; for (auto i : pos) { std::cerr << i << ' '; }*/ return count; }

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

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:9:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |   for (int i = 0; i < s.size(); i++) {
      |                   ~~^~~~~~~~~~
shoes.cpp:12:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |   for (int i = 0; i < s.size(); i++) {
      |                   ~~^~~~~~~~~~
shoes.cpp:17:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |   for (int i = 0; i < s.size(); i++) {
      |                   ~~^~~~~~~~~~
shoes.cpp:37:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   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...