結果

問題 No.1241 Eternal Tours
ユーザー 👑 hitonanodehitonanode
提出日時 2020-09-07 00:56:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,089 ms / 6,000 ms
コード長 4,219 bytes
コンパイル時間 2,299 ms
コンパイル使用メモリ 77,200 KB
実行使用メモリ 103,420 KB
最終ジャッジ日時 2024-05-06 23:59:43
合計ジャッジ時間 25,756 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
57,128 KB
testcase_01 AC 157 ms
56,908 KB
testcase_02 AC 780 ms
87,876 KB
testcase_03 AC 174 ms
57,704 KB
testcase_04 AC 157 ms
57,096 KB
testcase_05 AC 156 ms
56,976 KB
testcase_06 AC 156 ms
57,108 KB
testcase_07 AC 156 ms
56,960 KB
testcase_08 AC 163 ms
57,024 KB
testcase_09 AC 158 ms
57,076 KB
testcase_10 AC 161 ms
57,260 KB
testcase_11 AC 157 ms
56,832 KB
testcase_12 AC 161 ms
56,924 KB
testcase_13 AC 160 ms
57,028 KB
testcase_14 AC 685 ms
75,164 KB
testcase_15 AC 156 ms
57,372 KB
testcase_16 AC 485 ms
64,764 KB
testcase_17 AC 966 ms
103,248 KB
testcase_18 AC 945 ms
89,084 KB
testcase_19 AC 842 ms
87,204 KB
testcase_20 AC 187 ms
57,860 KB
testcase_21 AC 252 ms
59,244 KB
testcase_22 AC 988 ms
99,344 KB
testcase_23 AC 303 ms
61,848 KB
testcase_24 AC 159 ms
57,204 KB
testcase_25 AC 159 ms
57,336 KB
testcase_26 AC 149 ms
57,040 KB
testcase_27 AC 153 ms
56,928 KB
testcase_28 AC 916 ms
87,820 KB
testcase_29 AC 907 ms
88,008 KB
testcase_30 AC 949 ms
87,644 KB
testcase_31 AC 586 ms
73,392 KB
testcase_32 AC 933 ms
103,420 KB
testcase_33 AC 857 ms
87,524 KB
testcase_34 AC 1,089 ms
87,528 KB
testcase_35 AC 1,062 ms
87,908 KB
testcase_36 AC 156 ms
56,772 KB
testcase_37 AC 153 ms
57,080 KB
testcase_38 AC 873 ms
87,344 KB
testcase_39 AC 789 ms
87,452 KB
testcase_40 AC 1,069 ms
87,664 KB
testcase_41 AC 809 ms
103,156 KB
testcase_42 AC 688 ms
87,420 KB
testcase_43 AC 966 ms
87,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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

    static void ntt(int n, long[] a, long[] w)
    {
        if (n == 1) return;
        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;
                    if (a[i] >= md)
                    {
                        a[i] -= md;
                    }
                    a[i + m] = x - y + md;
                    if (a[i + m] >= md)
                    {
                        a[i + m] -= md;
                    }
                }
            }
        }
    }
    static void intt(int n, long[] a, long[] iw)
    {
        if (n == 1) return;
        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;
                    if (a[i] >= md)
                    {
                        a[i] -= md;
                    }
                    a[i + m] = (x - y + md) * iw[k] % md;
                }
            }
        }
        long n_inv = power(n, -1);
        for (int i = 0; i < n; i++)
        {
            a[i] = a[i] * n_inv % 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();
        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);

        long dp[][] = new long[H][W];
        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;

        long w[] = new long[1 << 17];
        long iw[] = new long[1 << 17];
        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], w);
            ntt(W, trans[i], w);
        }
        for (int j = 0; j < W; j++)
        {
            long dpv[] = new long[H];
            long transv[] = new long[H];
            for (int i = 0; i < H; i++)
            {
                dpv[i] = dp[i][j];
                transv[i] = trans[i][j];
            }
            ntt(H, dpv, w);
            ntt(H, transv, w);
            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;
            }
        }

        for (int j = 0; j < W; j++)
        {
            long dpv[] = new long[H];
            for (int i = 0; i < H; i++)
            {
                dpv[i] = dp[i][j];
            }
            intt(H, dpv, iw);
            for (int i = 0; i < H; i++)
            {
                dp[i][j] = dpv[i];
            }
        }
        intt(W, dp[c], iw);
        System.out.println(dp[c][d]);
    }
}
0