結果
| 問題 |
No.281 門松と魔法(1)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-09-10 11:34:12 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,424 bytes |
| コンパイル時間 | 1,068 ms |
| コンパイル使用メモリ | 76,672 KB |
| 最終ジャッジ日時 | 2025-01-14 09:14:01 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 47 RE * 10 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
using lint = long long;
bool judge(const std::vector<lint>& hs) {
return ((hs[0] < hs[1] && hs[1] > hs[2]) ||
(hs[0] > hs[1] && hs[1] < hs[2])) &&
hs[0] != hs[2];
}
constexpr lint INF = 1LL << 60;
void solve() {
lint d;
std::cin >> d;
std::vector<lint> hs(3);
for (auto& h : hs) std::cin >> h;
lint ans = INF;
{
auto nhs = hs;
lint cost = 0;
for (int i = 0; i < 3; i += 2) {
lint x = (nhs[i] < nhs[1] ? 0 : (nhs[i] - nhs[1]) / d + 1);
nhs[i] = std::max(0LL, nhs[i] - x * d);
cost += x;
}
if (nhs[0] == nhs[2]) {
nhs[0] = std::max(0LL, nhs[0] - d);
++cost;
}
if (judge(nhs)) ans = std::min(ans, cost);
}
{
auto nhs = hs;
lint cost = 0;
if (nhs[0] == nhs[2]) {
nhs[0] = std::max(0LL, nhs[0] - d);
++cost;
}
for (int i = 0; i < 3; i += 2) {
lint x = (nhs[1] < nhs[i] ? 0 : (nhs[1] - nhs[i]) / d + 1);
nhs[1] = std::max(0LL, nhs[1] - x * d);
cost += x;
}
if (judge(nhs)) ans = std::min(ans, cost);
}
std::cout << (ans == INF ? -1 : ans) << "\n";
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}