Submission #1033751

#TimeUsernameProblemLanguageResultExecution timeMemory
1033751enderArranging Shoes (IOI19_shoes)C++17
85 / 100
40 ms4432 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long count_swaps(std::vector<int> s) { if(s.size() > 2000){ long long ans = 0; int cl = 0, cr = 0; priority_queue<int, vector<int>, greater<int>> l, r; for(int i = 0; i < s.size(); ++i){ if(s[i] < 0) l.push(i); else r.push(i); } for(int i = 0; i < s.size(); ++i){ if(i%2 == 0){ if(s[i] > 0){ ans += l.top() - i; swap(s[i], s[l.top()]); r.pop(); r.push(l.top()); } l.pop(); }else { if(s[i] < 0){ ans += r.top() - i; swap(s[i], s[r.top()]); l.pop(); l.push(r.top()); } r.pop(); } } return ans; } long long ans = 0; for(int i = 0; i < s.size(); i += 2){ if(s[i] < 0){ for(int j = i+1; j < s.size(); ++j){ if(s[j] == -s[i]){ for(int k = j; k > i+1; --k){ swap(s[k], s[k-1]); ans++; } break; } } }else { int target = -s[i]; for(int j = i+1; j < s.size(); ++j){ if(s[j] == target){ for(int k = j; k > i; --k){ swap(s[k], s[k-1]); ans++; } break; } } } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:14:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for(int i = 0; i < s.size(); ++i){
      |                 ~~^~~~~~~~~~
shoes.cpp:21:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for(int i = 0; i < s.size(); ++i){
      |                 ~~^~~~~~~~~~
shoes.cpp:11:6: warning: unused variable 'cl' [-Wunused-variable]
   11 |  int cl = 0, cr = 0;
      |      ^~
shoes.cpp:11:14: warning: unused variable 'cr' [-Wunused-variable]
   11 |  int cl = 0, cr = 0;
      |              ^~
shoes.cpp:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for(int i = 0; i < s.size(); i += 2){
      |                 ~~^~~~~~~~~~
shoes.cpp:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |    for(int j = i+1; j < s.size(); ++j){
      |                     ~~^~~~~~~~~~
shoes.cpp:83:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |    for(int j = i+1; j < s.size(); ++j){
      |                     ~~^~~~~~~~~~
#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...