結果
問題 |
No.281 門松と魔法(1)
|
ユーザー |
![]() |
提出日時 | 2015-09-19 00:20:01 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,484 bytes |
コンパイル時間 | 790 ms |
コンパイル使用メモリ | 97,852 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-06 19:32:24 |
合計ジャッジ時間 | 2,231 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 41 WA * 16 |
コンパイルメッセージ
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:192:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 192 | scanf("%lld", &d); | ~~~~~^~~~~~~~~~~~ main.cpp:194:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 194 | scanf("%lld", &a[i]); | ~~~~~^~~~~~~~~~~~~~~
ソースコード
#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[4]; long long int d; long long int calculate_distance(int a, int b){ if (a > b){ swap(a, b); } swap(a, b); int dd = abs(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; } if (d==0LL){ return -1LL; } 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]){ if (d==0LL){ return -1LL; } countt += calculate_distance(a[0], a[1]); } if (a[2] >= a[1]){ if (d==0LL){ return -1LL; } 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; }