結果

問題 No.3068 Speedrun (Hard)
ユーザー sai
提出日時 2025-03-21 22:16:07
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 2,300 bytes
コンパイル時間 3,440 ms
コンパイル使用メモリ 276,312 KB
実行使用メモリ 7,328 KB
最終ジャッジ日時 2025-03-21 22:16:17
合計ジャッジ時間 10,712 ms
ジャッジサーバーID
(参考情報)
judge7 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 12 RE * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int A[4], B[4], N, T;
  for (int i = 0; i < 4; i++) {
    std::cin >> A[i];
  }
  std::cin >> N;
  for (int i = 0; i < 4; i++) {
    std::cin >> B[i];
  }
  std::cin >> T;
  auto check = [&](int x0, int x1, int x2, int x3) -> void {
    int X[4] = {x0, x1, x2, x3};
    int sum = 0, time = 0;
    for (int i = 0; i < 4; i++) {
      assert(0 <= X[i] && X[i] <= A[i]);
      sum += X[i];
      time += B[i] * X[i];
    }
    assert(sum == N);
    assert(time == T);
    std::cout << x0 << ' ' << x1 << ' ' << x2 << ' ' << x3 << '\n';
    exit(0);
  };
  if (B[0] == B[1] && B[1] == B[2] && B[2] == B[3]) {
    assert(A[0] + A[1] + A[2] + A[3] >= N);
    int x1 = A[1], x2 = A[2], x3 = A[3];
    for (int x0 = 0; x0 <= A[0]; x0++) {
      if (x0 + x1 + x2 + x3 == N) {
        check(x0, x1, x2, x3);
      }
    }
  } else {
    int idx1 = 0, idx2 = 1;
    for (int i = 0; i < 4; i++) {
      for (int j = i + 1; j < 4; j++) {
        if (B[i] != B[j]) {
          idx1 = i, idx2 = j;
        }
      }
    }
    assert(idx1 < idx2);
    assert(B[idx1] != B[idx2]);
    int idx3 = -1, idx4 = -1;
    for (int i = 0; i < 4; i++) {
      if (i != idx1 && i != idx2) {
        idx4 = i;
      }
    }
    assert(idx4 != -1);
    for (int i = 0; i < 4; i++) {
      if (i != idx1 && i != idx2 && i != idx4) {
        idx3 = i;
      }
    }
    assert(idx3 != -1);
    assert(idx3 < idx4);
    for (int x3 = 0; x3 <= A[idx3]; x3++) {
      for (int x4 = 0; x4 <= A[idx4]; x4++) {
        int P = B[idx2] * (N - x3 - x4) - (T - B[idx3] * x3 - B[idx4] * x4);
        int Q = B[idx2] - B[idx1];
        if (P % Q == 0 && 0 <= P / Q && P / Q <= A[idx1]) {
          int x1 = P / Q;
          int x2 = N - x1 - x3 - x4;
          int ans[4];
          std::fill(ans, ans + 4, -1);
          for (int i = 0; i < 4; i++) {
            if (i == idx1) {
              ans[i] = x1;
            }
            if (i == idx2) {
              ans[i] = x2;
            }
            if (i == idx3) {
              ans[i] = x3;
            }
            if (i == idx4) {
              ans[i] = x4;
            }
          }
          check(ans[0], ans[1], ans[2], ans[3]);
        }
      }
    }
  }
  assert(false);
}
0