結果
| 問題 |
No.281 門松と魔法(1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-10-31 20:37:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,857 bytes |
| コンパイル時間 | 1,717 ms |
| コンパイル使用メモリ | 166,724 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-19 12:45:01 |
| 合計ジャッジ時間 | 4,424 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 47 RE * 10 |
ソースコード
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (ll i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << (x) << endl
#define int long long
using namespace std;
using II = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { int n = d.size(); REP (i, n) s << d[i] << " "; return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& dd) { for (vector<T> d: dd) s << d << endl; return s; }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
const int MOD = 1e9 + 7;
int d;
// h2をでかくする
int solve1(int h1, int h2, int h3) {
int a1 = max(0ll, (h1 - h2 + d) / d);
int a3 = max(0ll, (h3 - h2 + d) / d);
h1 = max(0ll, h1 - d * a1);
h3 = max(0ll, h3 - d * a3);
if (h1 == h3 && h1 == 0) return 1e10;
return a1 + a3 + (h1 == h3);
}
// h2を小さくする
int solve2(int h1, int h2, int h3) {
int ans = 0;
if (h1 == h3) {
h1 = max(0ll, h1 - d);
ans++;
}
if (h1 == 0 || h3 == 0) return 1e10;
return ans + max(0ll, (h2 - min(h1, h3) + d) / d);
}
signed main() {
int h1, h2, h3;
cin >> d >> h1 >> h2 >> h3;
int ans = min(solve1(h1, h2, h3), solve2(h1, h2, h3));
cout << (ans == 1e10 ? -1 : ans) << endl;
}