제출 #295348

#제출 시각아이디문제언어결과실행 시간메모리
295348tzeroArranging Shoes (IOI19_shoes)C++14
컴파일 에러
0 ms0 KiB
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
using ll = long long;

int main() {
  int n;
  scanf("%d", &n);

  bool same_size = true;
  vector<int> s(n);
  for(int i = 0; i < 2 * n; i++) {
    scanf("%d", &s[i]);
    if(i > 0 && abs(s[i]) != abs(s[i - 1])) same_size = false;
  }

  if(n == 1) {
    if(s[0] < 0) {
      printf("0\n");
    } else {
      printf("1\n");
    }
  } else if(same_size) {
    ll move_left = 0, move_right = 0;
    int found_already = 0;
    for(int i = 0; i < 2 * n; i++) if(s[i] > 0) { 
      int pos = found_already++ * 2;
      move_left += abs(i - pos);
    }
    found_already = 0;
    for(int i = 0; i < 2 * n; i++) if(s[i] > 0) { 
      int pos = found_already++ * 2 + 1;
      move_right += abs(i - pos);
    }
    printf("%lld\n", min(move_left, move_right));
  } else {
    printf("%d\n", -1);
  }

  return 0;
}

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

shoes.cpp: In function 'int main()':
shoes.cpp:9:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
shoes.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |     scanf("%d", &s[i]);
      |     ~~~~~^~~~~~~~~~~~~
/tmp/ccFdz3D3.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc2UXD2B.o:shoes.cpp:(.text.startup+0x0): first defined here
/tmp/ccFdz3D3.o: In function `main':
grader.cpp:(.text.startup+0x26a): undefined reference to `count_swaps(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status