結果

問題 No.281 門松と魔法(1)
ユーザー itezpaceitezpace
提出日時 2016-10-24 09:24:26
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,303 bytes
コンパイル時間 359 ms
コンパイル使用メモリ 51,560 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-15 18:33:14
合計ジャッジ時間 4,928 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
using namespace std;
bool kadomatu(int a,int b,int c){
  if(b>a && b>c && a!=b && b!=c && c!=a){
    return true;
  } else if(b<a && b<c && a!=b && b!=c && c!=a){
    return true;
  } else {
    return false;
  }
}
int high(int a,int b,int c,int d){
  int ret=-1;
  if(kadomatu(a,b,c)){
    ret=0;
  } else {
    int x=0;
    if(a-d>=0 && a==c){
      a-=d;
      x+=1;
    }
    int g=a;
    if(a>b){
      int e=a-b;
      int f=e/d+1;
      g=a-d*f;
      if(g>0){
        x+=f;
      }
    }
    int h=c;
    if(c>b){
      int e=c-b;
      int f=e/d+1;
      h=c-d*f;
      if(h>0){
        x+=f;
      }
    }
    if(kadomatu(g,b,h)){
      ret=x;
    }
  }
  return ret;
}
int low(int a,int b,int c,int d){
  int ret=-1;
  if(kadomatu(a,b,c)){
    ret=0;
  } else {
    int x=0;
    if(a-d>=0 && a==c){
      a-=d;
      x+=1;
    }
    int e=a;
    if(c<a) e=a;
    int f=b-e;
    int g=f/d+1;
    if(b-d*g>0){
      x+=g;
    }
    if(kadomatu(a,b-d*g,c)){
      ret=x;
    }
  }
  return ret;
}
int main(){
  int d=0;cin>>d;
  int a=0,b=0,c=0;cin>>a>>b>>c;
  int ans=-1;
  int h=high(a,b,c,d);
  int l=low(a,b,c,d);
  if(h==-1){
    ans=l;
  } else if(l==-1){
    ans=h;
  } else {
    if(h<=l){
      ans=h;
    } else if(l<=h){
      ans=l;
    }
  }
  cout<<ans<<endl;
}
0