結果

問題 No.281 門松と魔法(1)
ユーザー ctyl_0ctyl_0
提出日時 2015-09-19 20:02:38
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,068 bytes
コンパイル時間 600 ms
コンパイル使用メモリ 86,212 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 11:49:13
合計ジャッジ時間 1,815 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int max_int = 2147483647;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

bool isTake(int a, int b, int c){
    if (a < 0 || b < 0 || c < 0){
        return false;
    }
    if ((a < b && b > c && a != c) || (a > b && b < c && a != c)) {
        return true;
    }
    return false;
}

bool isTakev(vector<int> V){
    return isTake(V[0], V[1], V[2]);
}

int main(int argc, const char * argv[]) {
    
    // source code
    int d = inputValue();
    vector<int> H(3);
    rep(i, 3){
        H[i] = inputValue();
    }
    // case -1
    
    if (isTake(H[0], H[1], H[2])) {
        output(0, 0);
        return 0;
    }
    
    if (!isTake(H[0], H[1], H[2]) && d == 0) {
        output(-1, 0);
        return 0;
    }
    
    // 真ん中を最小にする場合と最大にする場合両方調べる
    int seedC = 0;
    int seedE = 0;
    
    if (H[0] == H[2]) {
        H[0] = max(0, H[0] - d);
        if(H[0] != 0) {
            // 両端が0で同じだとどうしようもないので排除
            seedC += 1;
            seedE += 1;
        }
    }
    
    vector<int> newHC = H;
    // 真ん中を最小にしたい場合 (真ん中に魔法をかける)
    if (H[0] <= H[1] && H[0] <= H[2]) {
        newHC[1]  = H[1] - ((H[1] - H[0]) / d + 1) * d;
        seedC += (H[1] - H[0]) / d + 1;
        
    }
    if (H[0] <= H[1] && H[0] >= H[2]) {
        newHC[1]  = H[1] - ((H[1] - H[2]) / d + 1) * d;
        seedC += (H[1] - H[2]) / d + 1;
    }
    
    vector<int> newHE = H;
    // 真ん中を最大にしたい場合 (両端に魔法をかける)
    if (H[0] >= H[1]){
        newHE[0] = H[0] - ((H[0] - H[1]) / d + 1) * d;
        seedE += (H[0] - H[1]) / d + 1;
    }
    if (H[2] >= H[1]){
        newHE[2] = H[2] - ((H[2] - H[1]) / d + 1) * d;
        seedE += (H[2] - H[1]) / d + 1;
    }
    if (newHE[0] == newHE[2]){
        newHE[0] = max(0, newHE[0] - d);
        if(newHE[0] != 0) {
            // 両端が0で同じだとどうしようもないので排除
            seedE += 1;
        }
    }
    
    if (!isTakev(newHC)) {
        seedC = max_int;
    }
    if (!isTakev(newHE)) {
        seedE = max_int;
    }
    
    if (seedC == max_int && seedE == max_int) {
        output(-1, 0);
        return 0;
    }
    else{
        output(min(seedC, seedE), 0);
    }
    
    
    

    
    return 0;
}
0