Submission #153395

#TimeUsernameProblemLanguageResultExecution timeMemory
153395nandonathanielArranging Shoes (IOI19_shoes)C++14
45 / 100
34 ms3956 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL,LL> pii; pii pas[1005]; long long count_swaps(vector<int> s) { if((LL)s.size()<=2000){ vector<LL> hasil; LL n=(LL)s.size()/2; for(LL i=1;i<=n;i++)pas[i]={-1,-1}; for(int i=0;i<s.size();i++){ if(s[i]<0)pas[abs(s[i])].first=i; else pas[s[i]].second=i; if(pas[abs(s[i])].first!=-1 && pas[abs(s[i])].second!=-1){ pas[abs(s[i])].first=-1; pas[abs(s[i])].second=-1; } else{ hasil.push_back(-abs(s[i])); hasil.push_back(abs(s[i])); } } LL res=0; for(LL i=0;i<s.size();i++){ LL no; for(LL j=i;j<s.size();j++){ if(s[j]==hasil[i]){ no=j; break; } } for(LL j=no;j>=i+1;j--){ swap(s[j],s[j-1]); res++; } } return res; } vector<int> v; for(int i=0;i<s.size();i++){ if(s[i]<0)v.push_back(i); } LL now=0,ans=0; for(int i=0;i<s.size();i++){ if(i%2==0){ ans+=abs(v[now]-i); now++; } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:14:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<s.size();i++){
               ~^~~~~~~~~
shoes.cpp:27:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(LL i=0;i<s.size();i++){
              ~^~~~~~~~~
shoes.cpp:29:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(LL j=i;j<s.size();j++){
               ~^~~~~~~~~
shoes.cpp:43:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<s.size();i++){
              ~^~~~~~~~~
shoes.cpp:47:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<s.size();i++){
              ~^~~~~~~~~
shoes.cpp:28:7: warning: 'no' may be used uninitialized in this function [-Wmaybe-uninitialized]
    LL no;
       ^~
#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...