結果
問題 | No.2208 Linear Function |
ユーザー |
|
提出日時 | 2023-02-10 21:21:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 4,056 bytes |
コンパイル時間 | 3,982 ms |
コンパイル使用メモリ | 234,444 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-07 15:28:30 |
合計ジャッジ時間 | 3,725 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 3 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>#define pub push_back#define eb emplace_back#define mp make_pair#define fi first#define se second#define rep(i, n) rep2(i, 0, n)#define rep2(i, m, n) for (ll i = m; i < (n); i++)#define per(i, b) per2(i, 0, b)#define per2(i, a, b) for (ll i = int(b) - 1; i >= int(a); i--)#define ALL(c) (c).begin(), (c).end()using namespace std;using ll = long long;using Pll = pair<ll, ll>;using namespace atcoder;using mint = modint998244353;using mint2 = modint1000000007;constexpr long long INF = (1LL << 60);constexpr double EPS = 1e-9;constexpr double PI = 3.141592653589;template <typename T>bool chmax(T& a, const T& b) {if (a < b) {a = b; // aをbで更新return true;}return false;}template <typename T>bool chmin(T& a, const T& b) {if (a > b) {a = b; // aをbで更新return true;}return false;}template <typename T>T sq(T x) {return x * x;}std::string zfill(int n, const int width){std::stringstream ss;ss << std::setw(width) << std::setfill('0') << n;return ss.str();}//多倍長整数を(string→vector)に変換vector<ll> digit(string s) {ll n = s.size();vector<ll> d(n);rep(i, n) {d[i] = s[i] - '0';}return d;}//多倍長整数の足し算vector<ll> adds(vector<ll> s, vector<ll> t) {ll n = s.size();ll m = t.size();if (n > m) { swap(s, t); n = s.size(); m = t.size(); }reverse(ALL(s));reverse(ALL(t));rep(i, m - n) {s.pub(0);}bool kuriage = false;rep(i, m) {ll a = s[i];ll b = t[i];ll c = a + b;if (kuriage) {c++;}if (c >= 10) {c -= 10; kuriage = true;}else {kuriage = false;}t[i] = c;}if (kuriage) {t.pub(1);}reverse(ALL(t));return t;}vector<ll> carry_and_fix(vector<ll> digit) {int N = digit.size();for (int i = 0; i < N - 1; ++i) {// 繰り上がり処理 (K は繰り上がりの回数)if (digit[i] >= 10) {int K = digit[i] / 10;digit[i] -= K * 10;digit[i + 1] += K;}// 繰り下がり処理 (K は繰り下がりの回数)if (digit[i] < 0) {int K = (-digit[i] - 1) / 10 + 1;digit[i] += K * 10;digit[i + 1] -= K;}}// 一番上の桁が 10 以上なら、桁数を増やすことを繰り返すwhile (digit.back() >= 10) {int K = digit.back() / 10;digit.back() -= K * 10;digit.push_back(K);}// 1 桁の「0」以外なら、一番上の桁の 0 (リーディング・ゼロ) を消すwhile (digit.size() >= 2 && digit.back() == 0) {digit.pop_back();}reverse(ALL(digit));return digit;}//多倍長整数の掛け算(s × t) 計算量は N(|s||t|)?vector<ll> mul(vector<ll> s, vector<ll> t) {reverse(ALL(s));reverse(ALL(t));ll NA = s.size();ll NB = t.size();vector<ll> res(NA + NB - 1);for (int i = 0; i < NA; ++i) {for (int j = 0; j < NB; ++j) {res[i + j] += s[i] * t[j];}}return carry_and_fix(res);}/* make_is_prime(N)入力:整数 N出力:N までの数字が素数か判定したベクトル(i番目がtrueならiは素数)計算量:O(nloglogn)*/vector< bool > prime_table(int n) {vector< bool > prime(n + 1, true);if (n >= 0) prime[0] = false;if (n >= 1) prime[1] = false;for (int i = 2; i * i <= n; i++) {if (!prime[i]) continue;for (int j = i + i; j <= n; j += i) {prime[j] = false;}}return prime;}int main() {//cout << fixed << setprecision(10);ll t; cin >> t;rep(i, t) {ll l, r, a, b; cin >> l >> r >> a >> b;cout << max(l * a + b, r * a + b) << endl;}}