結果

問題 No.3462 Buttons
コンテスト
ユーザー karinohito
提出日時 2026-02-28 15:00:03
言語 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  
実行時間 116 ms / 2,000 ms
コード長 991 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,246 ms
コンパイル使用メモリ 338,308 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2026-02-28 15:00:14
合計ジャッジ時間 7,364 ms
ジャッジサーバーID
(参考情報)
judge3 / judge7
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

#include<atcoder/modint>
using namespace atcoder;
using mint=modint998244353;

mint solve(ll A,ll B,ll K){
    if(B==0||B==1){
        if(A>0)return A*K;
        else return 0;
    }
    else if(B==-1){
        if(A<0)return (-A)*(K-1);
        else return A*K;
    }
    if((B>=0&&A<0)||A==0){
        return 0;
    }
    else if(A<0){
        if(K<=1)return 0;
        if(K%2==1){
            return mint(A)*mint(B).pow(K-2)*2;
        }
        else{
            return mint(A)*mint(B).pow(K-1);
        }
    }
    else if(B>0){
        return mint(A)*mint(B).pow(K-1);
    }
    else if(K%2==1){
        return mint(A)*mint(B).pow(K-1);
    }
    else{
        return mint(A)*mint(B).pow(K-2)*2;
    }
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll T;
    cin>>T;
    while(T--){
        ll A,B,K;
        cin>>A>>B>>K;
        mint an=solve(A,B,K);
        cout<<an.val()<<"\n";
    }
}
0