結果

問題 No.281 門松と魔法(1)
ユーザー h_nosonh_noson
提出日時 2016-03-15 23:24:06
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,083 bytes
コンパイル時間 431 ms
コンパイル使用メモリ 61,096 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 12:02:31
合計ジャッジ時間 1,672 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define RREP(i,s,e) for (i = s; i >= e; i--)
#define rrep(i,n) RREP(i,n,0)
#define REP(i,s,e) for (i = s; i < e; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1e8

typedef long long ll;

int main() {
    int d, h1, h2, h3;
    cin >> d >> h1 >> h2 >> h3;
    if (h1 > h3)
        swap(h1,h3);
    if (h1 == 0 && h2 == 0 || h3 == 0)
        cout << -1 << endl;
    else if (h1 == h2 && h2 == h3) {
        if (h1 > d)
            cout << 3 << endl;
        else
            cout << -1 << endl;
    }
    else if (h1 == h3) {
        if (h1 < h2)
            cout << 1 << endl;
        else if (h1 < d)
            cout << -1 << endl;
        else if (h1 - d == h2) {
            if (h1 < 2*d)
                cout << -1 << endl;
            else
                cout << 2 << endl;
        }
        else
            cout << 1 << endl;

    }
    else if (h1 == h2) {
        if (d > 0 && h1 >= d)
            cout << 1 << endl;
        else
            cout << -1 << endl;
    }
    else if (h2 == h3) {
        if (h1 == h3 - d) {
            if (h3 > 2*d)
                cout << 2 << endl;
            else
                cout << -1 << endl;
        }
        else if (d > 0 && h3 >= d)
            cout << 1 << endl;
        else
            cout << -1 << endl;
    }
    else if ((h2 < h1 || h2 > h3))
        cout << 0 << endl;
    else if (d == 0)
        cout << -1 << endl;
    else {
        int x, y;
        x = (h2-h1)/d+1;
        if (h1 != max(0,h2 - x*d))
            x = (h2-h1)/d+1;
        else if (h1 != max(0,h2 - (x+1)*d))
            x++;
        else
            x = 1e9;
        y = (h3-h2)/d+1;
        if (h2 != max(0,h3 - y*d) && h1 != max(0,h3 - y*d))
            y = (h3-h2)/d+1;
        else if (h1 != max(0,h3 - (y+1)*d))
            y++;
        else if (h1 != max(0,h3 - (y+2)*d))
            y += 2;
        else
            y = 1e9;
        if (min(x,y) == 1e9)
            cout << -1 << endl;
        else
            cout << min(x,y) << endl;
    }
    return 0;
}
0