結果
| 問題 |
No.281 門松と魔法(1)
|
| コンテスト | |
| ユーザー |
nanasili
|
| 提出日時 | 2015-09-25 14:32:43 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,344 bytes |
| コンパイル時間 | 765 ms |
| コンパイル使用メモリ | 83,148 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-06 20:40:40 |
| 合計ジャッジ時間 | 2,206 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 57 |
ソースコード
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>
using namespace std;
typedef long long ll;
int main() {
ll d;
cin >> d;
ll a, b, c;
cin >> a >> b >> c;
if ((a < b && b > c && a != c) || (a > b && b < c && a != c)) {
puts("0");
}else if (b == 0 || d == 0) {
puts("-1");
}else {
ll ans = 0;
ll ta, tb, tc;
ta = a; tb = b; tc = c;
if (b <= a) {
ans += (a-b)/d+1;
ta = max(a-((a-b)/d)*d-d, 0LL);
}
if (b <= c) {
ans += (c-b)/d+1;
tc = max(c-((c-b)/d)*d-d, 0LL);
}
if (ta == tc && ta == 0) {
puts("-1");
}else {
if (ta == tc) ans++;
if (min(a, c) == 0) {
std::cout << ans << std::endl;
}else {
ta = a; tb = b; tc = c;
ll t = 0;
t += (b-min(a, c))/d+1;
tb = b-((b-min(a, c))/d)*d-d;
if (ta == tc) {
ta = max(0LL, ta-d);
t += 1;
}
if (ta == tb) {
tb = max(0LL, tb-d);
t += 1;
}
if (ta == tb) {
std::cout << ans << std::endl;
}else {
std::cout << min(ans, t) << std::endl;
}
}
}
}
}
nanasili