結果

問題 No.281 門松と魔法(1)
ユーザー ant2357ant2357
提出日時 2017-04-23 23:31:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,627 bytes
コンパイル時間 2,568 ms
コンパイル使用メモリ 168,104 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-09-29 16:06:33
合計ジャッジ時間 8,148 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 264 ms
4,384 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 653 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 TLE -
testcase_20 AC 79 ms
4,376 KB
testcase_21 AC 8 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 9 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 2 ms
4,380 KB
testcase_30 WA -
testcase_31 TLE -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

using LL = long long int;
using LD = long double;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

const int dy[] = { 0, 1, 0, -1 };
const int dx[] = { 1, 0, -1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
LL gcd(LL x, LL y) { return y ? gcd(y, x % y) : x; }

int d;
vi h(3);

bool kadomatuCheck(vi h) {
	if ((h[0] < h[1] && h[1] > h[2]) || (h[0] > h[1] && h[1] < h[2])) {
		return true;
	}

	return false;
}

int solve(vi take, int pos) {
	int res = 0;
	while (true) {
		take[pos] = take[pos] - d;
		if (take[pos] < 0) {
			return INF;
		}
		res++;

		if (kadomatuCheck(take)) {
			return res;
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> d;

	for (int i = 0; i < 3; i++) {
		cin >> h[i];
	}

	if (kadomatuCheck(h)) {
		cout << 0 << endl;
		return 0;
	}

	int ans1 = solve(h, 0);
	int ans2 = solve(h, 1);
	int ans3 = solve(h, 2);

	int ans = min(ans1, ans2);
	ans = min(ans, ans3);

	if (ans == INF) {
		ans = -1;
	}
	cout << ans << endl;
	return 0;
}
0