結果

問題 No.2631 Rectangle Grid Game
ユーザー kenken714kenken714
提出日時 2024-02-11 14:21:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,334 bytes
コンパイル時間 2,108 ms
コンパイル使用メモリ 201,752 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-12 12:34:45
合計ジャッジ時間 3,158 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
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 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 1 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 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) * y % mod;
    res += A * sum(y) * 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