제출 #1338663

#제출 시각아이디문제언어결과실행 시간메모리
1338663riafhasan2010Coin Collecting (JOI19_ho_t4)C++20
0 / 100
1 ms344 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 1e5 + 7;
int v[N][3];
int n;

pair<int, int> find_next(int x) {
  for (x; x <= n; x++) {
    for (int y = 1; y <= 2; y++) {
      if (v[x][y] > 1) return {x, y};
    }
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n * 2; i++) {
    int x, y; cin >> x >> y;
    if (x >= 1 and x <= n and y >= 1 and y <= 2) {
      v[x][y]++;
    }
    else if (x >= 1 and x <= n) {
      if (abs(2 - y) < abs(1 - y)) {
        ans += abs(2 - y);
        y = 2;
      }
      else {
        ans += abs(1 - y);
        y = 1;
      }
      v[x][y]++;
    }
    else if (y >= 1 and y <= 2) {
      if (abs(n - x) < abs(1 - x)) {
        ans += abs(n - x);
        x = n;
      }
      else {
        ans += abs(1 - x);
        x = 1;
      }
      v[x][y]++;
    }
    else {
      if (x <= 0 and y <= 0) {
        ans += abs(x - 1) + abs(y - 1);
        v[1][1]++;
      }
      else if (x > n and y <= 0) {
        ans += (x - n) + abs(y - 1);
        v[n][1]++;
      }
      else if (x <= 0 and y > 2) {
        ans += abs(x - 1) + abs(y - 2);
        v[1][2]++;
      }
      else {
        ans += abs(x - n) + abs(y - 2);
        v[n][2]++;
      }
    }
  }
  for (int i = 1, x = 1, y = 1; i <= n; i++) {
    for (int j = 1; j <= 2; j++) {
      if (v[x][y] <= 1) {
        auto [a, b] = find_next(x);
        x = a, y = b;
      }
      if (!v[i][j]) {
        ans += abs(x - i);
        ans += abs(y - j);
        v[x][y]--;
        v[i][j]++;
      }
    }
  }
  cout << ans << '\n';
}

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

joi2019_ho_t4.cpp: In function 'std::pair<int, int> find_next(int)':
joi2019_ho_t4.cpp:15:1: warning: control reaches end of non-void function [-Wreturn-type]
   15 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...