結果
| 問題 |
No.281 門松と魔法(1)
|
| コンテスト | |
| ユーザー |
satashun
|
| 提出日時 | 2015-09-18 22:36:21 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,164 bytes |
| コンパイル時間 | 1,445 ms |
| コンパイル使用メモリ | 158,624 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-06 18:31:15 |
| 合計ジャッジ時間 | 3,476 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 51 WA * 2 RE * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
int d;
int a, b, c, nb, nc;
ll res = LLONG_MAX;
int main() {
cin >> d >> b >> a >> c;
nb = b; nc = c;
if (a) {
ll t = 0;
if (b >= a) {
ll ad = (b - a) / d;
t += ad;
b -= d * ad;
if (b >= a) {
++t;
b = max(0, b - d);
}
}
if (c >= a) {
ll ad = (c - a) / d;
t += ad;
c -= d * ad;
if (c >= a) {
++t;
c = max(0, c - d);
}
}
if (b != 0 || c != 0) {
if (b != c) res = t;
else {
res = t + 1;
}
}
}
b = nb;
c = nc;
if (b > c) swap(b, c);
ll t = 0;
if (b == c) {
t = 1;
b = max(0, b - d);
}
if (b) {
ll ad = (a - b) / d;
t += ad;
a -= d * ad;
if (a >= b) {
++t;
a = max(0, a - d);
}
res = min(res, t);
}
if (res == LLONG_MAX) res = -1;
cout << res << endl;
return 0;
}
satashun