結果
問題 | No.2159 Filling 4x4 array |
ユーザー | 👑 Nachia |
提出日時 | 2022-10-30 22:41:45 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,522 bytes |
コンパイル時間 | 1,043 ms |
コンパイル使用メモリ | 82,868 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-14 22:56:48 |
合計ジャッジ時間 | 2,111 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
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 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | WA | - |
testcase_44 | WA | - |
testcase_45 | AC | 2 ms
5,248 KB |
testcase_46 | AC | 2 ms
5,248 KB |
testcase_47 | AC | 2 ms
5,248 KB |
testcase_48 | AC | 2 ms
5,248 KB |
testcase_49 | AC | 2 ms
5,248 KB |
ソースコード
#include <iostream> #include <atcoder/modint> using namespace std; using Int = atcoder::modint998244353; using LInt = __int128_t; Int f(LInt n){ return n < 0 ? 0 : (n+2) * (n+1) / 2; } Int Int_x0(Int n){ return n; } Int Int_x1(Int n){ return n * (n-1) / 2; } Int Int_x2(Int n){ return n * (n-1) * (2*n-1) / 6; } Int Int_x3(Int n){ return (n * (n-1) / 2).pow(2); } LInt Max(LInt a){ return a; } LInt Max(LInt a, LInt b){ return max(a, b); } LInt Max(LInt a, LInt b, LInt c){ return max(a, max(b, c)); } LInt Max(LInt a, LInt b, LInt c, LInt d){ return max(a, max(b, max(c, d))); } LInt Min(LInt a){ return a; } LInt Min(LInt a, LInt b){ return min(a, b); } LInt Min(LInt a, LInt b, LInt c){ return min(a, min(b, c)); } LInt Min(LInt a, LInt b, LInt c, LInt d){ return min(a, min(b, min(c, d))); } Int solve(LInt h1, LInt h2, LInt h3, LInt w1, LInt w2, LInt w3){ if(h1 + h2 + h3 != w1 + w2 + w3) return 0; LInt h = h2; LInt k = h1; Int ans = 0; Int static_coeff = (f(h) - f(h-(w1+w2+w3-k+3))); if (Max(0, k-w3-1-w2) < Min(k+1, w1+1)){ ans += (Int_x0(Min(k+1, w1+1)) - Int_x0(Max(0, k-w3-1-w2))) * (w2+1) * static_coeff; } if (Max(0, k-w3-1-w2, k-w2) < Min(k+1, w1+1)){ ans += (Int_x0(Min(k+1, w1+1)) - Int_x0(Max(0, k-w3-1-w2, k-w2))) * (k-w2) * static_coeff; ans += (Int_x1(Min(k+1, w1+1)) - Int_x1(Max(0, k-w3-1-w2, k-w2))) * (-1) * static_coeff; } if (Max(0, k-w3-1-w2) < Min(k+1, w1+1, k-w3+1)){ ans += (Int_x0(Min(k+1, w1+1, k-w3+1)) - Int_x0(Max(0, k-w3-1-w2))) * (w3-k) * static_coeff; ans += (Int_x1(Min(k+1, w1+1, k-w3+1)) - Int_x1(Max(0, k-w3-1-w2))) * (1) * static_coeff; } ans *= 2; for(int id=0; id<3; id++){ Int Coeff1X2 = -1; Int Coeff1X1 = -1+2*(-h+w1); Int Coeff1X0 = (-1)*(h-w1+1)*(h-w1); Int Coeff2X2 = 1; Int Coeff2X1 = 1-2*(h-w2-w3+k); Int Coeff2X0 = (h-w2-w3+k-1)*(h-w2-w3+k); if (Max(0, k-w3-1-w2, w1-h+1) < Min(k+1, w1+1)){ Int rangeL = Max(0, k-w3-1-w2, w1-h+1); Int rangeR = Min(k+1, w1+1); ans += (Int_x0(rangeR) - Int_x0(rangeL)) * (w2+1) * Coeff1X0; ans += (Int_x1(rangeR) - Int_x1(rangeL)) * (w2+1) * Coeff1X1; ans += (Int_x2(rangeR) - Int_x2(rangeL)) * (w2+1) * Coeff1X2; } if (Max(0, k-w3-1-w2, w1-h+1, k-w2) < Min(k+1, w1+1)){ Int rangeL = Max(0, k-w3-1-w2, w1-h+1, k-w2); Int rangeR = Min(k+1, w1+1); ans += (Int_x0(rangeR) - Int_x0(rangeL)) * (k-w2) * Coeff1X0; ans += (Int_x1(rangeR) - Int_x1(rangeL)) * (k-w2) * Coeff1X1; ans += (Int_x2(rangeR) - Int_x2(rangeL)) * (k-w2) * Coeff1X2; ans += (Int_x1(rangeR) - Int_x1(rangeL)) * (-1) * Coeff1X0; ans += (Int_x2(rangeR) - Int_x2(rangeL)) * (-1) * Coeff1X1; ans += (Int_x3(rangeR) - Int_x3(rangeL)) * (-1) * Coeff1X2; } if (Max(0, k-w3-1-w2, w1-h+1) < Min(k+1, w1+1, k-w3+1)){ Int rangeL = Max(0, k-w3-1-w2, w1-h+1); Int rangeR = Min(k+1, w1+1, k-w3+1); ans += (Int_x0(rangeR) - Int_x0(rangeL)) * (w3-k) * Coeff1X0; ans += (Int_x1(rangeR) - Int_x1(rangeL)) * (w3-k) * Coeff1X1; ans += (Int_x2(rangeR) - Int_x2(rangeL)) * (w3-k) * Coeff1X2; ans += (Int_x1(rangeR) - Int_x1(rangeL)) * (1) * Coeff1X0; ans += (Int_x2(rangeR) - Int_x2(rangeL)) * (1) * Coeff1X1; ans += (Int_x3(rangeR) - Int_x3(rangeL)) * (1) * Coeff1X2; } if (Max(0, k-w3-1-w2) < Min(k+1, w1+1, h-w2-w3+k-1)){ Int rangeL = Max(0, k-w3-1-w2); Int rangeR = Min(k+1, w1+1, h-w2-w3+k-1); ans += (Int_x0(rangeR) - Int_x0(rangeL)) * (w2+1) * Coeff2X0; ans += (Int_x1(rangeR) - Int_x1(rangeL)) * (w2+1) * Coeff2X1; ans += (Int_x2(rangeR) - Int_x2(rangeL)) * (w2+1) * Coeff2X2; } if (Max(0, k-w3-1-w2, k-w2) < Min(k+1, w1+1, h-w2-w3+k-1)){ Int rangeL = Max(0, k-w3-1-w2, k-w2); Int rangeR = Min(k+1, w1+1, h-w2-w3+k-1); ans += (Int_x0(rangeR) - Int_x0(rangeL)) * (k-w2) * Coeff2X0; ans += (Int_x1(rangeR) - Int_x1(rangeL)) * (k-w2) * Coeff2X1; ans += (Int_x2(rangeR) - Int_x2(rangeL)) * (k-w2) * Coeff2X2; ans += (Int_x1(rangeR) - Int_x1(rangeL)) * (-1) * Coeff2X0; ans += (Int_x2(rangeR) - Int_x2(rangeL)) * (-1) * Coeff2X1; ans += (Int_x3(rangeR) - Int_x3(rangeL)) * (-1) * Coeff2X2; } if (Max(0, k-w3-1-w2) < Min(k+1, w1+1, h-w2-w3+k-1, k-w3+1)){ Int rangeL = Max(0, k-w3-1-w2); Int rangeR = Min(k+1, w1+1, h-w2-w3+k-1, k-w3+1); ans += (Int_x0(rangeR) - Int_x0(rangeL)) * (w3-k) * Coeff2X0; ans += (Int_x1(rangeR) - Int_x1(rangeL)) * (w3-k) * Coeff2X1; ans += (Int_x2(rangeR) - Int_x2(rangeL)) * (w3-k) * Coeff2X2; ans += (Int_x1(rangeR) - Int_x1(rangeL)) * (1) * Coeff2X0; ans += (Int_x2(rangeR) - Int_x2(rangeL)) * (1) * Coeff2X1; ans += (Int_x3(rangeR) - Int_x3(rangeL)) * (1) * Coeff2X2; } LInt tmp = w1; w1 = w2; w2 = w3; w3 = tmp; } ans /= 2; return ans; } int main(){ long long h1, h2, h3, w1, w2, w3; cin >> h1 >> h2 >> h3 >> w1 >> w2 >> w3; h1 -= 3; h2 -= 3; h3 -= 3; w1 -= 3; w2 -= 3; w3 -= 3; Int ans = solve(h1, h2, h3, w1, w2, w3); cout << ans.val() << '\n'; return 0; }