結果

問題 No.281 門松と魔法(1)
ユーザー かにかに
提出日時 2015-09-19 05:12:48
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,624 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 92,528 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 11:47:26
合計ジャッジ時間 2,121 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#define aLL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXISt(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define MAX 100000000
#define pb push_back
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;
int dx[] = { 0,1,0,-1 };
int dy[] = { -1,0,1,0 };

int sttoi(std::string str) { int ret; std::stringstream ss; ss << str; ss >> ret; return ret; }
int par[MAX];
int ran[MAX];

int main() {
	ll n, a, b, c;
	cin >> n >> a >> b >> c;
	if (a < b && b > c && a != c) {
		P(0);
		return 0;
	}
	if (a > b && c > b && a != c) {
		P(0);
		return 0;
	}
	if (n == 0) {
		P(-1);
		return 0;
	}
	if (a == b && b == c && a == c) {
		if (a == n) {
			P(-1);
			return 0;
		}
		else if (a == 1) {
			P(-1);
		}
		else {
			P(3);
			return 0;
		}
	}
	else if (a == c) {
		if (a == 0) {
			P(-1);
		}
		else {
			P(2);
		}
		return 0;
	}
	else if (a < c) {
		if (max(a, max(b, c)) == b) {
			P(0);
			return 0;
		}
		else if (min(a, min(b, c)) == b) {
			P(0);
			return 0;
		}
		else {
			ll gap = min(abs(a - b), abs(b - c));
			if (gap == abs(a - b)) {
				if (a == 0) {
					if (c - (abs(b - c)/n + 1)*n < b && c - (abs(b - c)/n + 1)*n > 0) {
						P((int)(abs(b - c) / n + 1));
						return 0;
					}
					else {
						P(-1);
						return 0;
					}
				}
				else {
					P((int)gap / n + 1);
					return 0;
				}
			}
			else {
				if (b == 0) {
					P(-1);
					return 0;
				}
				else {
					P((int)gap / n + 1);
					return 0;
				}
			}
		}
	}
	else if (a > c) {
		if (max(a, max(b, c)) == b) {
			P(0);
			return 0;
		}
		else if (min(a, min(b, c)) == b) {
			P(0);
			return 0;
		}
		else {
			ll gap = min(abs(a - b), abs(b - c));
			if (gap == abs(b - c)) {
				if (c == 0) {
					P(-1);
					return 0;
				}
				else {
					P((int)gap / n + 1);
					return 0;
				}
			}
			else {
				if (b == 0) {
					P(-1);
					return 0;
				}
				else {
					P((int)gap / n + 1);
					return 0;
				}
			}
		}
	}
}
0