結果

問題 No.281 門松と魔法(1)
ユーザー nanasili
提出日時 2015-09-25 14:26:07
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,093 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 84,496 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-06 19:41:47
合計ジャッジ時間 2,178 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 55 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

int main() {
  ll d;
  cin >> d;
  ll a, b, c;
  cin >> a >> b >> c;
  if ((a < b && b > c && a != c) || (a > b && b < c && a != c)) {
    puts("0");
  }else if (b == 0 || d == 0) {
    puts("-1");
  }else {
    ll ans = 0;
    ll ta, tb, tc;
    ta = a; tb = b; tc = c;
    if (b <= a) {
      ans += (a-b)/d+1;
      ta = max(a-((a-b)/d)*d-d, 0LL);
    }
    if (b <= c) {
      ans += (c-b)/d+1;
      tc = max(c-((c-b)/d)*d-d, 0LL);
    }
    if (ta == tc && ta == 0) {
      puts("-1");
    }else {
      if (ta == tc) ans++;
      if (min(a, c) == 0) {
	std::cout << ans << std::endl;
      }else {
	std::cout << min(ans, (b-min(a, c))/d+1) << std::endl;
      }
    }
  }
}
0