結果

問題 No.281 門松と魔法(1)
ユーザー furafura
提出日時 2020-06-09 19:24:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 979 bytes
コンパイル時間 1,915 ms
コンパイル使用メモリ 199,000 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-30 19:08:57
合計ジャッジ時間 4,433 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

const long long INF=1LL<<61;

bool is_kadomatsu(lint a,lint b,lint c){
	if(a==b || a==c || b==c) return false;
	if(a<b && b>c) return true;
	if(a>b && b<c) return true;
	return false;
}

int main(){
	lint d,a,b,c; cin>>d>>a>>b>>c;

	if(d==0){
		puts(is_kadomatsu(a,b,c)?"0":"-1");
		return 0;
	}

	lint ans=INF;
	// b が最大値になるケース
	{
		lint ta=a,tb=b,tc=c;

		lint res=0;
		if(a>=b){
			lint k=(a-b)/d+1;
			res+=k;
			a-=k*d;
		}
		if(c>=b){
			lint k=(c-b)/d+1;
			res+=k;
			c-=k*d;
		}
		if(a==c) a-=d, res++;
		if(a>=0 && b>=0 && c>=0){
			ans=min(ans,res);
		}

		a=ta; b=tb; c=tc;
	}
	// b が最小値になるケース
	{
		lint res=0;
		if(a==c) a-=d, res++;
		if(b>=min(a,c)){
			lint k=(b-min(a,c))/d+1;
			res+=k;
			b-=k*d;
		}
		if(a>=0 && b>=0 && c>=0){
			ans=min(ans,res);
		}
	}
	printf("%lld\n",ans<INT_MAX?ans:-1);

	return 0;
}
0