結果

問題 No.281 門松と魔法(1)
ユーザー tottoripapertottoripaper
提出日時 2015-09-28 21:42:58
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,538 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 36,456 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-24 11:55:04
合計ジャッジ時間 1,575 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 0 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 1 ms
5,376 KB
testcase_17 WA -
testcase_18 AC 1 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 0 ms
5,376 KB
testcase_23 WA -
testcase_24 AC 1 ms
5,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 0 ms
5,376 KB
testcase_30 AC 1 ms
5,376 KB
testcase_31 WA -
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 0 ms
5,376 KB
testcase_34 AC 0 ms
5,376 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 0 ms
5,376 KB
testcase_38 AC 1 ms
5,376 KB
testcase_39 AC 0 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 0 ms
5,376 KB
testcase_42 AC 0 ms
5,376 KB
testcase_43 AC 0 ms
5,376 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 0 ms
5,376 KB
testcase_47 WA -
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 0 ms
5,376 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 AC 1 ms
5,376 KB
testcase_53 AC 1 ms
5,376 KB
testcase_54 AC 1 ms
5,376 KB
testcase_55 WA -
testcase_56 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |     scanf("%d", &d);
      |     ~~~~~^~~~~~~~~~
main.cpp:12:31: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |     for(int i=0;i<3;i++){scanf("%d", H+i);}
      |                          ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <algorithm>
#include <limits>

int d;
int H[3];

const int INF = std::numeric_limits<int>::max();

int main(){
    scanf("%d", &d);
    for(int i=0;i<3;i++){scanf("%d", H+i);}

    if(d == 0){
        puts((H[0] == H[1] || H[1] == H[2] || H[2] == H[0])
            ? "-1"
            : "0");
        return 0;
    }
    
    int res = INF;
    
    // 中央の木を最大にしたい
    {
        int s = std::max((H[0] - H[1]) / d, 0),
            t = std::max((H[2] - H[1]) / d, 0);
        int a = std::max(H[0] - s * d, 0),
            b = std::max(H[2] - t * d, 0);

        if(a == H[1]){a = std::max(a - d, 0); s += 1;}
        if(b == H[1]){b = std::max(b - d, 0); t += 1;}
        
        if(a != b){
            res = s + t;
        }else if(!(a == 0 && b == 0)){
            res = s + t + 1;
        }
    }

    // printf("1st: %d\n", res);
    
    // 中央の木を最小にしたい
    {
        int count = 0;
        
        if(H[0] == H[2]){
            H[0] = std::max(H[0] - d, 0);
            count += 1;
        }

        int t = std::max({ (H[1] - H[0]) / d
                         , (H[1] - H[2]) / d
                         , 0
                         } );
        int x = std::max(H[1] - t * d, 0);

        if(x == H[0] || x == H[2]){
            x = std::max(x - d, 0);
            count += 1;
        }
        
        if(!((H[0] == 0 || H[2] == 0) && x == 0)){
            res = std::min(res, t + count);
        }
    }

    printf("%d\n", (res == INF) ? -1 : res);
}
0