結果
問題 | No.281 門松と魔法(1) |
ユーザー |
![]() |
提出日時 | 2015-09-19 18:14:11 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,408 bytes |
コンパイル時間 | 654 ms |
コンパイル使用メモリ | 84,352 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-06 19:35:30 |
合計ジャッジ時間 | 2,192 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 56 WA * 1 |
ソースコード
#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; }