結果

問題 No.281 門松と魔法(1)
ユーザー itezpace
提出日時 2016-10-24 09:24:26
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,303 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 56,720 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-24 02:40:36
合計ジャッジ時間 3,154 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20 WA * 28 RE * 9
権限があれば一括ダウンロードができます

ソースコード

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