제출 #295381

#제출 시각아이디문제언어결과실행 시간메모리
295381tzeroArranging Shoes (IOI19_shoes)C++14
30 / 100
41 ms3200 KiB
#include <iostream>
#include <vector>
#include <math.h>
#include <cassert>
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);
        found_left++;
      } else {
        int pos = found_right * 2 + 1;
        move_right += abs(i - pos);
        found_right++;
      }
    }
    return min(move_left, move_right);
  } else {
    return -1;
  }
}

int _main() {
  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;
}

컴파일 시 표준 에러 (stderr) 메시지

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