제출 #988296

#제출 시각아이디문제언어결과실행 시간메모리
988296kachim2Arranging Shoes (IOI19_shoes)C++17
100 / 100
445 ms281804 KiB
#include "shoes.h" #include <climits> #include <queue> #include <vector> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; long long count_swaps(std::vector<int> s) { std::vector<int> pos(s.size(), INT_MIN); auto qm = new std::queue<int>[s.size()+1]; auto qp = new std::queue<int>[s.size()+1]; for (int i = 0; i < s.size(); i++) { if (s[i] < 0) { if (qp[-s[i]].empty()) { qm[-s[i]].push(i); } else { auto x = qp[-s[i]].front(); qp[-s[i]].pop(); pos[i] = x; } } else { if (qm[s[i]].empty()) { qp[s[i]].push(i); } else { auto x = qm[s[i]].front(); qm[s[i]].pop(); pos[i] = x; } } } long count = 0; tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update> B; for (int i = 0; i < s.size(); i++) { B.insert(i * 3 + 1); } for (int i = 0; i < s.size(); i++) { if (pos[i] >= 0) { if (s[i] > 0) { count += B.order_of_key(i * 3 + 1) - B.order_of_key(pos[i] * 3 + 1) - 1; B.erase(i * 3 + 1); B.insert(pos[i] * 3 + 2); } else { count += B.order_of_key(i * 3 + 1) - B.order_of_key(pos[i] * 3 + 1); B.erase(i * 3 + 1); B.insert(pos[i] * 3); } } } delete[] qm; delete[] qp; return count; }

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

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