Submission #295372

#TimeUsernameProblemLanguageResultExecution timeMemory
295372tzeroArranging Shoes (IOI19_shoes)C++14
10 / 100
1 ms256 KiB
#include <iostream> #include <vector> #include <math.h> using namespace std; using ll = long long; ll count_swaps(vector<int> s) { int n = (int)s.size(); bool same_size = true; for(int i = 0; i < n; i++) { if(i > 0 && abs(s[i]) != abs(s[i - 1])) same_size = false; } if(n == 2) { if(s[0] < 0) return 0; else return 1; } else if(same_size) { ll move_left = 0, move_right = 0; int found_left = 0, found_right = 0; for(int i = 0; i < n; i++) { if(s[i] > 0) { int pos = found_left++ * 2; move_left += abs(i - pos); } else { int pos = found_right++ * 2 + 1; move_right += abs(i - pos); } } return min(move_left, move_right); } else { return -1; } } int mmain() { int n; scanf("%d", &n); vector<int> _s(2 * n); for(int i = 0; i < n; i++) { scanf("%d", &_s[i]); } printf("%lld\n", count_swaps(_s)); return 0; }

Compilation message (stderr)

shoes.cpp: In function 'int mmain()':
shoes.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
shoes.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   42 |     scanf("%d", &_s[i]);
      |     ~~~~~^~~~~~~~~~~~~~
#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...