結果

問題 No.3462 Buttons
コンテスト
ユーザー hikikomori
提出日時 2026-02-19 17:59:33
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 526 ms / 2,000 ms
コード長 2,345 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 6,865 ms
コンパイル使用メモリ 378,256 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-02-28 13:09:03
合計ジャッジ時間 16,741 ms
ジャッジサーバーID
(参考情報)
judge7 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<ll>>;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvll = vector<vll>;
using vs = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<long long, long long>;
using vpll = vector<pll>;
using mint = modint998244353;
const long double EPS = 1e-18;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
#define reps(i, a, n) for (ll i = (a); i < (ll)(n); i++)
#define rep(i, n) for (ll i = (0); i < (ll)(n); i++)
#define rrep(i, n) for (ll i = (1); i < (ll)(n + 1); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define rrepd(i, n) for (ll i = n; i >= 1; i--)
#define ALL(n) begin(n), end(n)
#define IN(a, x, b) (a <= x && x < b)
#define INIT                          \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(0);
template <class T>
inline T CHMAX(T& a, const T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline T CHMIN(T& a, const T b) {
    return a = (a > b) ? b : a;
}
void solve() {
    ll A, B, K;
    cin >> A >> B >> K;

    mint ans = 0;
    if (K > 1) {
        if (A > 0) {
            if (B >= 2) {
                ans = mint(A) * mint(B).pow(K - 1);
            } else if (B <= -2) {
                if (K % 2) {
                    ans = mint(A) * mint(B).pow(K - 1);
                } else {
                    ans = mint(2 * A) * mint(B).pow(K - 2);
                }
            } else {
                ans = mint(A)*mint(K);
            }
        } else if (A < 0) {
            if (B <= -2) {
                if (!(K % 2)) {
                    ans = mint(A) * mint(B).pow(K - 1);
                } else {
                    ans = mint(2 * A) * mint(B).pow(K - 2);
                }
            } else if (B >= 0) {
                ans = 0;
            } else {
               ans = mint(-A) * mint(K - 1);
            }
        } else {
            ans = 0;
        }
    } else {
        ll res = max(0ll, A);
        ans = mint(res);
    }
    cout << ans.val() << endl;
}
int main() {
    INIT;
    ll T;
    cin >> T;
    while (T--) solve();
    return 0;
}
0