結果

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

テストケース

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

ソースコード

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==c){
      a-=d;
      if(a<0) a=0;
      x+=1;
    }
    int g=a;
    if(a>b){
      int e=a-b;
      int f=e/d+1;
      g=a-d*f;
      if(g<0) 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) 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==c){
      a-=d;
      if(a<0) a=0;
      x+=1;
    }
    int e=a;
    if(c<a) e=c;
    int f=b-e;
    int g=f/d+1;
    int h=b-d*g;
    if(h<0) h=0;
    x+=g;
    if(kadomatu(a,h,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;
  if(d==0){
    if(kadomatu(a,b,c)){
      ans=0;
    }
  } else {
    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