結果

問題 No.1241 Eternal Tours
ユーザー 👑 hitonanodehitonanode
提出日時 2020-09-07 01:24:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 762 ms / 6,000 ms
コード長 3,584 bytes
コンパイル時間 4,581 ms
コンパイル使用メモリ 77,032 KB
実行使用メモリ 77,588 KB
最終ジャッジ日時 2024-04-21 11:08:19
合計ジャッジ時間 22,401 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 143 ms
44,652 KB
testcase_01 AC 148 ms
44,180 KB
testcase_02 AC 596 ms
68,984 KB
testcase_03 AC 149 ms
44,504 KB
testcase_04 AC 147 ms
44,712 KB
testcase_05 AC 145 ms
44,656 KB
testcase_06 AC 142 ms
44,484 KB
testcase_07 AC 147 ms
44,188 KB
testcase_08 AC 145 ms
44,572 KB
testcase_09 AC 141 ms
44,200 KB
testcase_10 AC 145 ms
44,084 KB
testcase_11 AC 145 ms
44,496 KB
testcase_12 AC 148 ms
44,248 KB
testcase_13 AC 145 ms
44,676 KB
testcase_14 AC 456 ms
58,700 KB
testcase_15 AC 148 ms
44,360 KB
testcase_16 AC 355 ms
50,556 KB
testcase_17 AC 541 ms
76,400 KB
testcase_18 AC 544 ms
70,092 KB
testcase_19 AC 634 ms
67,728 KB
testcase_20 AC 168 ms
44,788 KB
testcase_21 AC 187 ms
45,520 KB
testcase_22 AC 577 ms
69,016 KB
testcase_23 AC 275 ms
46,736 KB
testcase_24 AC 144 ms
44,136 KB
testcase_25 AC 146 ms
44,176 KB
testcase_26 AC 143 ms
44,032 KB
testcase_27 AC 144 ms
43,984 KB
testcase_28 AC 719 ms
69,144 KB
testcase_29 AC 593 ms
69,516 KB
testcase_30 AC 602 ms
69,384 KB
testcase_31 AC 381 ms
54,944 KB
testcase_32 AC 513 ms
76,324 KB
testcase_33 AC 608 ms
64,428 KB
testcase_34 AC 762 ms
69,540 KB
testcase_35 AC 713 ms
69,408 KB
testcase_36 AC 143 ms
44,600 KB
testcase_37 AC 145 ms
43,988 KB
testcase_38 AC 612 ms
64,592 KB
testcase_39 AC 614 ms
64,472 KB
testcase_40 AC 755 ms
69,088 KB
testcase_41 AC 688 ms
77,588 KB
testcase_42 AC 624 ms
64,420 KB
testcase_43 AC 744 ms
69,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    final static long md = 998244353;
    final static long root = 3;

    final static long w[] = new long[1 << 17];
    final static long iw[] = new long[1 << 17];

    static void ntt(int n, long[] a)
    {
        for (int m = n / 2; m > 0; m /= 2)
        {
            for (int s = 0, k = 0; s < n; s += 2 * m, k++)
            {
                for (int i = s; i < s + m; i++)
                {
                    long x = a[i], y = a[i + m] * w[k] % md;
                    a[i] = (x + y >= md ? x + y - md : x + y);
                    a[i + m] = (x - y < 0 ? x + md - y : x - y);
                }
            }
        }
    }
    static void intt(int n, long[] a)
    {
        for (int m = 1; m < n; m *= 2)
        {
            for (int s = 0, k = 0; s < n; s += 2 * m, k++)
            {
                for (int i = s; i < s + m; i++)
                {
                    long x = a[i], y = a[i + m];
                    a[i] = (x + y >= md ? x + y - md : x + y);
                    a[i + m] = (x - y + md) * iw[k] % md;
                }
            }
        }
    }

    static long power(long x, long n)
    {
        if (n == -1)
        {
            n = md - 2;
        }
        x %= md;
        long ans = 1;
        long tmp = x;
        while (n > 0)
        {
            if ((n & 1) == 1)
            {
                ans = ans * tmp % md;
            }
            tmp = tmp * tmp % md;
            n /= 2;
        }
        return ans;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        final int X = sc.nextInt();
        final int Y = sc.nextInt();
        final long T = (sc.nextLong() - 1) % (md - 1) + 1;
        final int a = sc.nextInt();
        final int b = sc.nextInt();
        final int c = sc.nextInt();
        final int d = sc.nextInt();

        final int H = 1 << (X + 1);
        final int W = 1 << (Y + 1);

        final long dp[][] = new long[H][W];
        final long trans[][] = new long[H][W];

        dp[a][b] = 1;
        dp[a][W - b] = -1;
        dp[H - a][b] = -1;
        dp[H - a][W - b] = 1;
        trans[0][0] = trans[0][1] = trans[1][0] = trans[H - 1][0] = trans[0][W - 1] = 1;

        w[0] = iw[0] = 1;
        for (int m = 1; m < 1 << 17; m *= 2)
        {
            long dw = power(root, (md - 1) / (4 * m));
            long dwinv = power(dw, -1);
            for (int i = 0; i < m; i++)
            {
                w[m + i] = w[i] * dw % md;
                iw[m + i] = iw[i] * dwinv % md;
            }
        }

        for (int i = 0; i < H; i++)
        {
            ntt(W, dp[i]);
            ntt(W, trans[i]);
        }

        final long dpv[] = new long[H];
        final long transv[] = new long[H];

        for (int j = 0; j < W; j++)
        {
            for (int i = 0; i < H; i++)
            {
                dpv[i] = dp[i][j];
                transv[i] = trans[i][j];
            }
            ntt(H, dpv);
            ntt(H, transv);
            for (int i = 0; i < H; i++)
            {
                dp[i][j] = dpv[i];
                trans[i][j] = transv[i];
            }
        }

        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                dp[i][j] = dp[i][j] * power(trans[i][j], T) % md;
            }
            intt(W, dp[i]);
        }

        for (int i = 0; i < H; i++)
        {
            dpv[i] = dp[i][d];
        }
        intt(H, dpv);
        System.out.println(dpv[c] * power(H * W, -1) % md);
    }
}
0