Submission #196982

#TimeUsernameProblemLanguageResultExecution timeMemory
196982BasilhijazArranging Shoes (IOI19_shoes)C++14
0 / 100
1026 ms3576 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long count_swaps(std::vector<int> s) { int cnt = 0; long long swaps = 0; vector <int> a(s.size()); for(int i = 0; i < s.size(); i++){ if(s[i] < 0){ swaps += abs(i - (cnt * 2)); a[cnt*2] = s[i]; cnt++; } } cnt = 0; for(int i = s.size() - 1; i>=0; i--){ if(s[i]<0){ cnt++; } else if(i >= s.size() - (cnt*2) - 2){ s[i+cnt] = s[i]; s[i] = 0; } } for(int i = 0; i < s.size(); i++){ if(s[i] > 0){ for(int j = 0; j < s.size(); j+=2){ if(a[j] == s[i]*-1){ swaps += abs((j+1) - i); } } } } return swaps; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:7:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < s.size(); i++){
                    ~~^~~~~~~~~~
shoes.cpp:19:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         else if(i >= s.size() - (cnt*2) - 2){
                 ~~^~~~~~~~~~~~~~~~~~~~~~~~~
shoes.cpp:24:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < s.size(); i++){
                    ~~^~~~~~~~~~
shoes.cpp:26:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int j = 0; j < s.size(); j+=2){
                            ~~^~~~~~~~~~
#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...