답안 #478553

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478553 2021-10-08T01:36:52 Z Mackerel_Pike Coin Collecting (JOI19_ho_t4) C++14
0 / 100
1 ms 204 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5 + 5;

int n;
long long ans = 0;
int cnt[maxn][2];

int main(){
  //freopen("c.in", "r", stdin);
  //freopen("c.out", "w", stdout);
  
  scanf("%d", &n);
  for(int i = 0; i < n * 2; ++i){
    int x, y; scanf("%d%d", &x, &y);
    int nx = max(1, min(n, x)), ny = max(1, min(2, y));
    ++cnt[nx][ny], ans += abs(nx - x) + abs(ny - y);
  }
  for(int i = 1; i <= n; ++i){
    if(cnt[i][1] < 1 && cnt[i][2] > 1)
      ans += 1 - cnt[i][1], cnt[i][2] += cnt[i][1] - 1, cnt[i][1] = 1;
    if(cnt[i][2] < 1 && cnt[i][1] > 1)
      ans += 1 - cnt[i][2], cnt[i][1] += cnt[i][2] - 1, cnt[i][2] = 1;
    ans += abs(cnt[i][1] - 1), cnt[i + 1][1] += cnt[i][1] - 1, cnt[i][1] = 1;
    ans += abs(cnt[i][2] - 1), cnt[i + 1][2] += cnt[i][2] - 1, cnt[i][2] = 1;
  }

  printf("%lld\n", ans);
  return 0;
}

Compilation message

joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
joi2019_ho_t4.cpp:17:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     int x, y; scanf("%d%d", &x, &y);
      |               ~~~~~^~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:22:33: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   22 |     if(cnt[i][1] < 1 && cnt[i][2] > 1)
      |                         ~~~~~~~~^
joi2019_ho_t4.cpp:23:39: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   23 |       ans += 1 - cnt[i][1], cnt[i][2] += cnt[i][1] - 1, cnt[i][1] = 1;
      |                             ~~~~~~~~~~^~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:24:16: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   24 |     if(cnt[i][2] < 1 && cnt[i][1] > 1)
      |        ~~~~~~~~^
joi2019_ho_t4.cpp:25:65: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   25 |       ans += 1 - cnt[i][2], cnt[i][1] += cnt[i][2] - 1, cnt[i][2] = 1;
      |                                                         ~~~~~~~~^
joi2019_ho_t4.cpp:27:24: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   27 |     ans += abs(cnt[i][2] - 1), cnt[i + 1][2] += cnt[i][2] - 1, cnt[i][2] = 1;
      |                ~~~~~~~~^
joi2019_ho_t4.cpp:27:46: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   27 |     ans += abs(cnt[i][2] - 1), cnt[i + 1][2] += cnt[i][2] - 1, cnt[i][2] = 1;
      |                                ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
joi2019_ho_t4.cpp:27:46: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
joi2019_ho_t4.cpp:27:72: warning: array subscript 2 is above array bounds of 'int [2]' [-Warray-bounds]
   27 |     ans += abs(cnt[i][2] - 1), cnt[i + 1][2] += cnt[i][2] - 1, cnt[i][2] = 1;
      |                                                                ~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 0 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 0 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Incorrect 0 ms 204 KB Output isn't correct
7 Halted 0 ms 0 KB -