結果

問題 No.281 門松と魔法(1)
ユーザー ctyl_0ctyl_0
提出日時 2015-09-18 23:14:42
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,921 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 82,636 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 11:29:54
合計ジャッジ時間 1,835 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 WA -
testcase_03 AC 1 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 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 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 2 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 WA -
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 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 WA -
testcase_34 AC 1 ms
5,376 KB
testcase_35 WA -
testcase_36 AC 1 ms
5,376 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 2 ms
5,376 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 1 ms
5,376 KB
testcase_46 AC 2 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 WA -
testcase_52 AC 2 ms
5,376 KB
testcase_53 AC 1 ms
5,376 KB
testcase_54 AC 2 ms
5,376 KB
testcase_55 WA -
testcase_56 WA -
権限があれば一括ダウンロードができます

ソースコード

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;

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 < b && b > c && a != c) || (a > b && b < c && a != c)) {
        return true;
    }
    return false;
}

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 ((H[0] == 0 && H[1] == 0) || (H[1] == 0 && H[2] == 0) || (H[0] == 0 && H[2] == 0)) {
        output(-1, 0);
        return 0;
    }
    
    if (d == 0 && !isTake(H[0], H[1], H[2])) {
        output(-1, 0);
        return 0;
    }
    
    // case どれかが0
    if (H[1] == 0) {
        output((H[0] == H[2]) ? 1 : 0, 0);
        return 0;
    }
    
    if (H[0] == 0) {
        int ret = (H[1] > H[2]) ? 0 : (H[2] - H[1]) / d + 1;
        output(ret, 0);
        return 0;
    }
    
    if (H[2] == 0) {
        int ret = (H[1] > H[0]) ? 0 : (H[0] - H[1]) / d + 1;
        output(ret, 0);
        return 0;
    }
    
    if (isTake(H[0], H[1], H[2])) {
        output(0, 0);
        return 0;
    }
    
    int ret = min((H[1] - H[0]) / d + 1, (H[2] - H[1]) / d + 1);
    
    output(ret, 0);
    

    
    return 0;
}
0