結果

問題 No.281 門松と魔法(1)
ユーザー Lepton_sLepton_s
提出日時 2015-09-19 18:14:11
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,408 bytes
コンパイル時間 615 ms
コンパイル使用メモリ 82,944 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 11:47:50
合計ジャッジ時間 1,829 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 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 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 1 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 1 ms
5,376 KB
testcase_21 AC 1 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 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 2 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 1 ms
5,376 KB
testcase_37 AC 1 ms
5,376 KB
testcase_38 AC 1 ms
5,376 KB
testcase_39 AC 1 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 WA -
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 1 ms
5,376 KB
testcase_44 AC 1 ms
5,376 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 1 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 2 ms
5,376 KB
testcase_50 AC 1 ms
5,376 KB
testcase_51 AC 1 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 1 ms
5,376 KB
testcase_56 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
typedef pair<int,int> P;
typedef long long ll;
typedef unsigned long long ull;

ll INF = 1e12;

int main(){
	ll d, a, b, c;
	cin>>d>>a>>b>>c;
	if(a>c) swap(a, c);
	ll res = INF;
	if(b > c && c > a) res = 0;
	if(b < a && c > a) res = 0;
	if(d==0){
		cout<<(res==INF?-1:res)<<endl;
		return 0;
	}
	cerr<<res<<endl;
	ll a2 = a, b2 = b, c2 = c;
	{ // b > max(a, c)
		ll t1 = 0, t2 = 0;
		if(a>=b){
			t1 = (a-b)/d+1;
			a -= d*t1;
			if(a<0) a = 0;
		}
		if(c>=b){
			t2 = (c-b)/d+1;
			c -= d*t2;
			if(c<0) c = 0;
			if(c==a){
				t2++;
				c -= d;
			}
			if(c<0) c = 0;
		}
		if(a==c) t2 = INF;
		res = min(res, t1+t2);
	}
	cerr<<res<<endl;
	a = a2; b = b2; c = c2;
	{ // b < min(a, c)
		ll t1 = 0, t2 = 0;
		if(a==c){
			t1++;
			a -= d;
		}
		if(a<=0) t1 = INF;
		if(a<=b){
			t2 = (b-a)/d+1;
			b -= d*t2;
		}
		if(b<0) b = 0;
		if(b==a){
			t2++;
			b -= d;
		}
		if(b<0) b = 0;
		if(a==b) t2 = INF;
		res = min(res, t1+t2);
	}
	cout<<(res==INF?-1:res)<<endl;
	return 0;
}
0