結果

問題 No.2099 [Cherry Alpha B] Time Machine
ユーザー TaniiGoTaniiGo
提出日時 2022-10-14 22:50:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,490 bytes
コンパイル時間 1,965 ms
コンパイル使用メモリ 193,196 KB
最終ジャッジ日時 2025-02-08 04:31:39
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 54 WA * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define all(a) begin(a), end(a)
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

ll modpow(ll a, ll b, ll m) {
	ll p = a;
	ll ans = 1;
	rep(i,32) {
		if ((b & (0x01 << i)) != 0) {
			ans *= p;
			ans %= m;
		}
		p *= p;
		p %= m;
	}
	return (ans);
}

ll pow(ll a, ll b) {
	ll p = a;
	ll ans = 1;
	rep(i,32) {
		if ((b & (0x01 << i)) != 0) {
			ans *= p;
		}
		p *= p;
	}
	return (ans);
}

ll Division(ll a, ll b, ll m) {
	return ((a * modpow(b, m - 2, m)) % m);
}

struct V {
	int x, y;
	V(int x=0, int y=0): x(x), y(y) {}
	V operator-(const V &a) const {
		return V(x-a.x, y-a.y);
	}
	int cross(const V &a) const {
		return x*a.y - y*a.x;
	}
	int ccw(const V &a) const {
		int area = cross(a);
		if (area > 0) return +1; // ccw
		if (area < 0) return -1; // cw
		return 0; // collinear
	}
};

/*
	2147483648 int max
	1000000000 1e9
	9223372036854775807 ll max
	1000000000000000000 1e18
*/

int main() {
	int t;
	cin >> t;
	int x, a, y, b;
	cin >> x >> a >> y >> b;

	if (t > 0) {
		int now = 0;
		int c0 = (t-now)/a*x;
		c0 += t%a;

		now = 0;
		int c1 = ((t+a-1)/a)*x;
		now = (t+a-1)/a*a;
		c1 += (now-t+b-1)/b*y;
		now -= (now-t+b-1)/b*b;
		c1 += (t-now);

		now = 0;
		int c2 = (t+a+b-1)/a*x;
		now = (t+a+b-1)/a*a;
		c2 += (now-t+b-1)/b*y;
		now -= (now-t+b-1)/b*b;
		c2 += (t-now)/a*x;
		now += (t-now)/a*a;
		c2 += t-now;
		chmin(c0,c1);
		chmin(c0,c2);
		cout << c0 << endl;
	}
	else {
		t = -t;
		int now = 0;
		int c0 = (t-now+b-1)/b*y;
		now = (t-now+b-1)/b*b;
		c0 += (now-t)/a*x;
		now -= (now-t)/a*a;
		c0 += abs(t-now);

		now = 0;
		int c1 = (t-now+a+b-1)/b*y;
		now = (t-now+a+b-1)/b*b;
		c1 += (now-t)/a*x;
		now -= (now-t)/a*a;
		c1 += (now-t);

		now = 0;
		int c2 = (t-now+a-1)/b*y;
		now = (t-now+a-1)/b*b;
		c2 += (now-t)/a*x;
		now -= (now-t)/a*a;
		c2 += (now-t);
		chmin(c1,c2);

		cout << min(c0,c1) << endl;
	}
	return 0;
}
0