結果

問題 No.281 門松と魔法(1)
ユーザー sugim48
提出日時 2015-09-18 22:42:48
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,229 bytes
コンパイル時間 763 ms
コンパイル使用メモリ 81,204 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-06 18:42:22
合計ジャッジ時間 2,328 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 47 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int solve(int a, int b, int c, int d) {
	if (b < a && b < c && a != c) return 0;
	if (b > a && b > c && a != c) return 0;
	if (d == 0) return -1;
	int cnt = 0;
	if (a == c) {
		if (a == 0) return -1;
		cnt++;
		a = max(a, a - d);
	}
	int x = (b - min(a, c) + d - 1) / d;
	if (min(a, c) == 0) x = INT_MAX;
	int y = (max(0, a - b + 1) + d - 1) / d + (max(0, c - b + 1) + d - 1) / d;
	if (b == 0) y = INT_MAX;
	int z = min(x, y);
	if (z == INT_MAX) return -1;
	return z + cnt;
}

int main() {
	int d, a, b, c; cin >> d >> a >> b >> c;
	cout << solve(a, b, c, d) << endl;
}
0