Problem Solving/Codeforces

[코드포스 / Codeforces] Round #901 (Div. 2)

nageune 2023. 10. 9. 09:29
728x90
반응형

Codeforces Round #901 (Div. 2)

문제 세트는 여기서 확인할 수 있다.


문제

A. Jellyfish and Undertale (AC+1 / 38 min)

더보기

타이머가 1초일 때마다 가장 작은 도구를 써주면 된다. 사실 풀이의 이유는 모르지만 직접 손으로 써보고 찾은 규칙대로 코드를 짰다.

 

#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
  cin.tie(0)->sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    int a, b, n;
    cin >> a >> b >> n;
    int ans = b, cnt = 0;
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      ans += min(a, x);
      if (x >= a)
        cnt++;
    }
    cout << ans - cnt << '\n';
  }
}

 

B.Jellyfish and Game (AC+2 / 1 hour 18 min)

더보기

문제가 좀 불친절했다. 항상 둘 다 최선을 다하기 때문에 라운드의 홀짝성에 따라 결과가 달라진다.

모든 케이스를 나눠서 생각해줬다. 대신 처음에 바꾸지 않을 수도 있다는 것에 유의해야 한다.

#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
  cin.tie(0)->sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m, k, x;
    cin >> n >> m >> k;
    int a_min = 1e18, a_max = 0, a_sum = 0;
    int b_min = 1e18, b_max = 0, b_sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> x;
      a_min = min(a_min, x);
      a_max = max(a_max, x);
      a_sum += x;
    }
    for (int i = 0; i < m; i++) {
      cin >> x;
      b_min = min(b_min, x);
      b_max = max(b_max, x);
      b_sum += x;
    }
    int total_max = max(a_max, b_max);
    int total_min = min(a_min, b_min);
    if (a_min < b_max) {
      if (a_max >= b_max && a_min >= b_min) {
        if (k % 2) {
          cout << a_sum - a_min + b_max;
        } else {
          cout << a_sum - a_max - a_min + b_max + b_min;
        }
      } else if (a_max >= b_max && a_min < b_min) {
        if (k % 2) {
          cout << a_sum - a_min + b_max;
        } else {
          cout << a_sum - a_max + b_max;
        }
      } else if (a_max < b_max && a_min < b_min) {
        if (k % 2) {
          cout << a_sum - a_min + b_max;
        } else {
          cout << a_sum;
        }
      } else if (a_max < b_max && a_min >= b_min) {
        if (k % 2) {
          cout << a_sum - a_min + b_max;
        } else {
          cout << a_sum - a_min + b_min;
        }
      }
    } else {
      if (k % 2) {
        cout << a_sum;
      } else {
        cout << a_sum - a_max + b_min;
      }
    }
    cout << '\n';
  }
}

 

C.Jellyfish and Green Apple (WA)

더보기

1kg인 사과 n개를 m명에게 정확히 똑같이 나눠주기 위해서 몇 번의 칼질을 해야하는지 구하는 문제. 칼질은 정확히 조각을 반으로 나눈다. 내 코드는 틀린게 없다. 뭐가 문제냐 대체. 왜 TLE를 돌려주는 것이냐!!!


총평

난이도 자체가 높았던 것 같다. 평소와 비슷하거나 더 늦게 문제를 풀었고 패널티도 몇번 받았는데 평소보다 퍼포가 훨씬 높다. A, B의 AC 수도 되게 천천히 올라가던걸 봤다. 덕분에 오랜만에 레이팅이 올랐다.. ㅎㅎ 문제가 불친절해서 좀 별로였다.

728x90
반응형