結果

問題 No.281 門松と魔法(1)
ユーザー kk
提出日時 2021-03-15 22:45:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,231 bytes
コンパイル時間 2,024 ms
コンパイル使用メモリ 200,900 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-07 07:40:08
合計ジャッジ時間 5,591 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 RE -
testcase_32 RE -
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 RE -
testcase_44 AC 1 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 RE -
testcase_47 AC 2 ms
4,380 KB
testcase_48 RE -
testcase_49 RE -
testcase_50 RE -
testcase_51 AC 2 ms
4,376 KB
testcase_52 RE -
testcase_53 RE -
testcase_54 RE -
testcase_55 AC 2 ms
4,384 KB
testcase_56 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

const long long INF = 1LL<<50;

long long minimize(int d, vector<int> h) {
  long long ret = 0;

  if (h[0] == h[2]) {
    h[0] = max(h[0] - d, 0);
    ++ret;
  }
  
  if (h[1] < min(h[0], h[2])) {
    return ret;
  }

  int t = (h[1] - min(h[0], h[2])) / d + 1;
  ret += t;
  h[1] = max(h[1] - t * d, 0);

  if (h[0] != h[1] && h[1] != h[2] && h[2] != h[0] && h[1] < min(h[0], h[2]))
    return ret;
  
  return INF;
}

long long maximize(int d, vector<int> h) {
  long long ret = 0;

  if (h[0] >= h[1]) {
    int t = (h[0] - h[1]) / d + 1;
    ret += t;
    h[0] = max(0, h[0] - t * d);
  }

  if (h[2] >= h[1]) {
    int t = (h[2] - h[1]) / d + 1;
    ret += t;
    h[2] = max(0, h[2] - t * d);
  }

  if (h[0] == h[2]) {
    h[0] = max(h[0] - d, 0);
    ++ret;
  }

  if (h[0] != h[1] && h[1] != h[2] && h[2] != h[0] && h[1] > max(h[0], h[2]))
    return ret;
  
  return INF;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  int d;
  vector<int> h(3);

  cin >> d;
  for (int i = 0; i < 3; i++)
    cin >> h[i];

  long long ret = min(minimize(d, h), maximize(d, h));
  if (ret == INF)
    cout << -1 << endl;
  else
    cout << ret << endl;
  
  return 0;
}
0