結果

問題 No.281 門松と魔法(1)
ユーザー srjywrdnprkt
提出日時 2023-01-16 04:58:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 995 bytes
コンパイル時間 1,188 ms
コンパイル使用メモリ 108,436 KB
最終ジャッジ日時 2025-02-10 03:40:22
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 47 RE * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;

int main(){

    int mi=2e9+100, cnt, d, s, use;
    vector<int> a(3), b;
    cin >> d;
    for (int i=0; i<3; i++) cin >> a[i];

    b=a; cnt=0;
    if (b[0] == b[2]){
        cnt=1;
        b[0] = max(0, b[0]-d);
    }
    s = min(b[0], b[2]);
    use = max(0, (b[1]-s+1+d-1)/d);
    b[1] = max(0, b[1]-use*d);
    cnt += use;
    if (b[0] != b[1] && b[1] != b[2]) mi = min(mi, cnt);

    b=a; cnt=0;
    use = max(0, (b[0]-b[1]+1+d-1)/d);
    b[0] = max(0, b[0]-use*d);
    cnt += use;
    use = max(0, (b[2]-b[1]+1+d-1)/d);
    b[2] = max(0, b[2]-use*d);
    cnt += use;
    if (b[0] == b[2]){
        cnt++;
        b[0] = max(0, b[0]-d);
    }
    if (b[0] != b[2]) mi = min(mi, cnt);

    cout << (mi == 2e9+100 ? -1 : mi) << endl;

    return 0;
}
0