結果
問題 |
No.281 門松と魔法(1)
|
ユーザー |
![]() |
提出日時 | 2016-04-13 13:48:53 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,635 bytes |
コンパイル時間 | 594 ms |
コンパイル使用メモリ | 84,912 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-06 19:51:18 |
合計ジャッジ時間 | 2,269 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 55 RE * 2 |
ソースコード
/* -*- coding: utf-8 -*- * * 281.cc: No.281 門松と魔法(1) - yukicoder */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int INF = 1 << 30; /* typedef */ /* global variables */ /* subroutines */ inline bool is_kadomatsu(int h0, int h1, int h2) { return (h0 != h2 && ((h0 < h1 && h1 > h2) || (h0 > h1 && h1 < h2))); } void finish(int ans) { printf("%d\n", ans); exit(0); } /* main */ int main() { int d, h0, h1, h2; cin >> d >> h0 >> h1 >> h2; int cnt = 0; if (h0 == h2) { h0 = max(0, h0 - d); cnt++; if (h0 == h2) finish(-1); } if (is_kadomatsu(h0, h1, h2)) finish(cnt); // keep h0 < h2 if (h0 > h2) swap(h0, h2); // h0 < h1 > h2 int c0 = INF; if (h1 > 0) { c0 = cnt; int ch0 = h0, ch2 = h2; if (ch0 >= h1) { int e = (ch0 - h1) / d + 1; c0 += e; ch0 = max(ch0 - e * d, 0); } if (ch2 >= h1) { int e = (ch2 - h1) / d + 1; c0 += e; ch2 = max(ch2 - e * d, 0); } if (ch0 == ch2) { if (ch0 == 0) c0 = INF; else c0++; } } // h0 > h1 < h2 int c1 = INF; if (h0 > 0) { c1 = cnt; int ch1 = h1; if (h0 <= ch1) { int e = (ch1 - h0) / d + 1; c1 += e; ch1 = max(ch1 - e * d, 0); } } int c = min(c0, c1); finish((c >= INF) ? -1 : c); return 0; }