結果

問題 No.2631 Rectangle Grid Game
ユーザー kenken714kenken714
提出日時 2024-02-12 12:34:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,346 bytes
コンパイル時間 2,116 ms
コンパイル使用メモリ 201,880 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-12 12:34:48
合計ジャッジ時間 3,204 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 1 ms
6,676 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 5 ms
6,676 KB
testcase_23 AC 1 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1ll << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll H, W, mod = 998244353;
ll sum(ll n){
    n %= mod;
    return n * (n + 1) / 2 % mod;
}

ll solve1(ll x, ll y){
    //Σ HW - (A - i)(B - j)
    ll A, B;
    A = (H % 2 == 1 ? (H + 3) / 2 : (H + 4) / 2);
    B = (W % 2 == 1 ? (W + 3) / 2 : (W + 4) / 2);

    ll res = 0;
    res += (H * W - A * B) % mod * x % mod * y % mod;
    res += B * sum(x) % mod * y % mod;
    res += A * sum(y) % mod * x % mod;
    res -= sum(x) * sum(y) % mod;
    res = (res % mod + mod) % mod;
    return res;
}

ll solve2(){
    if(H % 2 == 1 and W % 2 == 1){
        ll ans = 0;
        REP(i, 2)REP(j, 2) ans += solve1((H + i) / 2, (W + j) / 2);
        return ans % mod;
    }
    if(H % 2 == 0 and W % 2 == 0){
        return solve1(H / 2, W / 2) * 4 % mod;
    }
    if(H % 2 == 0)swap(H, W);
    return (2 * solve1((H + 1) / 2, W / 2) + 2 * solve1(H / 2, W / 2)) % mod;
}

int main(){
    cin >> H >> W;
    cout << solve2() << endl;
}
0