結果
| 問題 |
No.281 門松と魔法(1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-09-20 20:59:34 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 780 bytes |
| コンパイル時間 | 440 ms |
| コンパイル使用メモリ | 57,284 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-06 19:40:25 |
| 合計ジャッジ時間 | 2,995 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 48 RE * 9 |
ソースコード
#include <algorithm>
#include <cassert>
#include <iostream>
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
using namespace std;
typedef long long int ll;
const int inf = 1.1e9;
int f(int d, int h1, int h2, int h3) {
assert (h1 != h3);
if (h1 < h3) {
swap(h1, h3);
}
if (h3 < 0) { return -1; }
if (h2 > h1 || h2 < h3) {
return 0;
}
int sub1 = h3 == 0 ? inf : (h2 - h3 + 1 + d - 1) / d;
int sub2 = (h1 - h2 + d) / d;
if (max(h1 - sub2 * d, 0) == h3) { sub2 = h3 == 0 ? inf : (sub2 + 1); }
sub1 = min(sub1, sub2);
return sub1 == inf ? -1 : sub1;
}
int main(void){
int d, h1, h2, h3;
cin >> d >> h1 >> h2 >> h3;
if (h1 == h3) {
int r = f(d, h1, h2, h3 - d);
cout << (r < 0 ? -1 : r + 1) << endl;
return 0;
}
cout << f(d, h1, h2, h3) << endl;
}