結果

問題 No.281 門松と魔法(1)
ユーザー Kmcode1Kmcode1
提出日時 2015-09-18 23:44:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,364 bytes
コンパイル時間 809 ms
コンパイル使用メモリ 97,912 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 11:42:12
合計ジャッジ時間 2,743 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 WA -
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 2 ms
6,944 KB
testcase_22 AC 1 ms
6,940 KB
testcase_23 AC 2 ms
6,940 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 WA -
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,944 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 1 ms
6,940 KB
testcase_30 WA -
testcase_31 RE -
testcase_32 RE -
testcase_33 WA -
testcase_34 AC 2 ms
6,940 KB
testcase_35 WA -
testcase_36 AC 1 ms
6,944 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 RE -
testcase_44 AC 1 ms
6,940 KB
testcase_45 AC 1 ms
6,940 KB
testcase_46 AC 1 ms
6,944 KB
testcase_47 AC 1 ms
6,940 KB
testcase_48 AC 1 ms
6,940 KB
testcase_49 AC 1 ms
6,940 KB
testcase_50 RE -
testcase_51 WA -
testcase_52 AC 2 ms
6,944 KB
testcase_53 AC 1 ms
6,944 KB
testcase_54 WA -
testcase_55 AC 2 ms
6,940 KB
testcase_56 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘long long int solve_min()’:
main.cpp:113:1: warning: control reaches end of non-void function [-Wreturn-type]
  113 | }
      | ^
main.cpp: In function ‘int main()’:
main.cpp:183:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  183 |         scanf("%lld", &d);
      |         ~~~~~^~~~~~~~~~~~
main.cpp:185:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  185 |                 scanf("%lld", &a[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_map>
#include<unordered_set>
//#include<quadmath.h>
using namespace std;
long long int a[3];
long long int tmp[3];
long long int d;
int calculate_distance(int a, int b){
	if (a > b){
		swap(a, b);
	}
	swap(a, b);
	int dd = a - b;
	dd /= d;
	dd++;
	return dd;
}
long long int solve_min(){
	if (a[0] == 0 || a[2] == 0){
		return -1LL;
	}
	if (a[0] == a[1] || a[1] == a[2]){
		return -1LL;
	}
	bool update = true;
	while (update){
		update = false;
		if (a[0] < a[1]){
			int k = a[1] - a[0];
			if (k <= d || k%d == 0){
				return -1LL;
			}
		}
		if (a[2] < a[1]){
			int k = a[1] - a[2];
			if (k <= d || k%d == 0){
				return -1LL;
			}
		}
		return calculate_distance(min(a[0], a[2]), a[1]);
		if (a[0] < a[1] && a[2] < a[1]){
			int countt = 0;
			int ta;
			int tb;
			if (a[0] > a[2]){
				int tep = a[0]-a[2];
				tep /= d;
				if (tep*d < a[0] - a[2]){
					tep++;
				}
				ta = max(static_cast<int>(a[0]-tep*d),0);
				tb = a[2];
				countt += tep;
			}
			else{
				int tep = a[2] - a[0];
				tep /= d;
				if (tep*d < a[2] - a[0]){
					tep++;
				}
				tb = max(static_cast<int>(a[2]-tep*d),0);
				ta = a[0];
				countt += tep;
			}
			if (ta == tb){
				countt += calculate_distance(ta, a[1]);
			}
			else{
				countt += calculate_distance(ta, a[1]);
				countt += calculate_distance(tb, a[1]);
			}
			return countt;
		}
		else{
			if (a[0] < a[1]){
				return calculate_distance(a[0], a[1]);
			}
			else{
				if (a[2] < a[1]){
					return calculate_distance(a[2], a[1]);
				}
				else{
					return 0LL;
				}
			}
		}
	}
}
long long int solve_max(){
	if (a[0] == a[1] || a[1] == a[2]){
		return -1LL;
	}
	if (a[0] > a[1]){
		if ((a[0] - a[1]) % d == 0){
			return -1LL;
		}
	}
	if (a[2] > a[1]){
		if ((a[2] - a[1]) % d == 0){
			return -1LL;
		}
	}
	if (a[0] < a[2]){
		swap(a[0], a[2]);
	}
	if (a[0] > a[1] && a[2] > a[1]){
		int countt = 0;
		int ta;
		int tb;
		int dist = a[0] - a[2];
		if (dist%d){
			return calculate_distance(max(a[0],a[2]),a[1]);
		}
		else{
			return calculate_distance(a[0], a[1]) + calculate_distance(a[0], a[2]);
		}
	}
	else{
		if (a[0] > a[1]){
			return calculate_distance(a[0], a[1]);
		}
		else{
			if (a[2] > a[1]){
				return calculate_distance(a[1], a[2]);
			}
			else{
				return 0LL;
			}
		}
	}
}
long long int solvemin(){
	long long int k = min(a[0], a[2]);
	if (k > a[1]){
		return 0;
	}
	else{
		if (k == 0){
			return -1;
		}
		return calculate_distance(a[1], k);
	}
}
long long int solvemax(){
	long long int countt = 0;
	if (a[1] == 0){
		return -1LL;
	}
	if (a[0] >= a[1]){
		countt += calculate_distance(a[0], a[1]);
	}
	if (a[2] >= a[1]){
		countt += calculate_distance(a[1], a[2]);
	}
	return countt;
}
int main(){
	scanf("%lld", &d);
	for (int i = 0; i < 3; i++){
		scanf("%lld", &a[i]);
	}
	long long int ans = solvemin();
	if (ans != -1LL){
		ans = min(ans, solvemax());
	}
	else{
		ans = solvemax();
	}
	printf("%lld\n", ans);
	return 0;
}
0