Submission #158381

#TimeUsernameProblemLanguageResultExecution timeMemory
158381ismagilovArranging Shoes (IOI19_shoes)C++14
50 / 100
1089 ms3324 KiB
#include<bits/stdc++.h> using namespace std ; long long count_swaps (vector<int>s) { int n = s.size(); bool c=1; long long ans = 0 ; for(int i = 0 ;i<=n/2;i++) { if(s[i]!=-s[2*i-1]){c=0;break;} } n=n/2LL; if(c)return n*(n-1)/2LL; for(int i = 0 ;i < s.size();i+=2) { int j = i+1; while(s[i]!=-s[j]) { j++; } while (j!=i+1) { swap(s[j],s[j-1]); ans++; j--; } if(s[j]<0) { swap(s[i],s[j]); ans++; } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:14:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int i = 0 ;i < s.size();i+=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...