結果
| 問題 | No.281 門松と魔法(1) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-24 09:54:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,411 bytes |
| 記録 | |
| コンパイル時間 | 573 ms |
| コンパイル使用メモリ | 55,628 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-24 02:41:20 |
| 合計ジャッジ時間 | 2,038 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 57 |
ソースコード
#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;
}