Submission #597552

#TimeUsernameProblemLanguageResultExecution timeMemory
597552FatihSolakArranging Shoes (IOI19_shoes)C++17
50 / 100
1089 ms1876 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long count_swaps(vector<int> s){ long long ans = 0; int n = s.size(); long long x = n/2; for(int i = 0;i<n;i+=2){ int mini = -1; int val = 1e9; for(int j = i;j<n;j++){ if(s[j] < 0){ for(int c = i;c<n;c++){ if(s[c] == -s[j]){ int nowval = j - i; nowval += (c - (i+1)) + (j >c); if(nowval < val){ val = nowval; mini = s[j]; } break; } } } } for(int j = i;j<n;j++){ if(s[j] == mini){ for(int c = j-1;c>=i;c--){ swap(s[c],s[c+1]); ans++; } break; } } for(int j = i+1;j<n;j++){ if(s[j] == -s[i]){ for(int c = j-1;c>=i+1;c--){ swap(s[c],s[c+1]); ans++; } break; } } } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:7:12: warning: unused variable 'x' [-Wunused-variable]
    7 |  long long x = n/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...