結果

問題 No.1241 Eternal Tours
ユーザー 👑 hos.lyrichos.lyric
提出日時 2020-09-06 15:19:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 964 ms / 6,000 ms
コード長 3,860 bytes
コンパイル時間 2,620 ms
コンパイル使用メモリ 86,828 KB
実行使用メモリ 81,864 KB
最終ジャッジ日時 2024-05-07 00:00:53
合計ジャッジ時間 21,355 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
54,120 KB
testcase_01 AC 112 ms
53,064 KB
testcase_02 AC 463 ms
70,956 KB
testcase_03 AC 115 ms
53,056 KB
testcase_04 AC 123 ms
54,208 KB
testcase_05 AC 121 ms
53,972 KB
testcase_06 AC 123 ms
53,856 KB
testcase_07 AC 111 ms
54,196 KB
testcase_08 AC 124 ms
53,908 KB
testcase_09 AC 121 ms
54,172 KB
testcase_10 AC 127 ms
53,720 KB
testcase_11 AC 124 ms
54,644 KB
testcase_12 AC 122 ms
53,988 KB
testcase_13 AC 124 ms
54,028 KB
testcase_14 AC 489 ms
66,360 KB
testcase_15 AC 119 ms
53,984 KB
testcase_16 AC 377 ms
62,100 KB
testcase_17 AC 964 ms
81,864 KB
testcase_18 AC 791 ms
73,072 KB
testcase_19 AC 784 ms
71,088 KB
testcase_20 AC 145 ms
54,024 KB
testcase_21 AC 154 ms
54,116 KB
testcase_22 AC 920 ms
79,852 KB
testcase_23 AC 192 ms
54,412 KB
testcase_24 AC 123 ms
53,656 KB
testcase_25 AC 128 ms
53,628 KB
testcase_26 AC 110 ms
52,820 KB
testcase_27 AC 125 ms
53,712 KB
testcase_28 AC 602 ms
71,128 KB
testcase_29 AC 593 ms
70,832 KB
testcase_30 AC 653 ms
70,992 KB
testcase_31 AC 477 ms
64,148 KB
testcase_32 AC 954 ms
81,840 KB
testcase_33 AC 887 ms
72,424 KB
testcase_34 AC 747 ms
71,220 KB
testcase_35 AC 737 ms
71,040 KB
testcase_36 AC 121 ms
54,380 KB
testcase_37 AC 122 ms
54,384 KB
testcase_38 AC 895 ms
72,328 KB
testcase_39 AC 827 ms
69,940 KB
testcase_40 AC 774 ms
71,124 KB
testcase_41 AC 822 ms
81,824 KB
testcase_42 AC 649 ms
69,900 KB
testcase_43 AC 592 ms
70,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import static java.lang.Math.*;
import static java.math.BigInteger.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class Main {
  public static void main(String[] args) { new Main().run(); }
  Scanner in = new Scanner(System.in);
  void _out(Object...os) { System.out.println(deepToString(os)); }
  void _err(Object...os) { System.err.println(deepToString(os)); }
  
  final long MO = 998244353;
  final long G = 3;
  
  void run() {
    for (; in.hasNext(); ) {
      int X = in.nextInt();
      int Y = in.nextInt();
      long T = in.nextLong();
      int A = in.nextInt();
      int B = in.nextInt();
      int C = in.nextInt();
      int D = in.nextInt();
      
      int m = 1 << (X + 1);
      int n = 1 << (Y + 1);
      
      long[] gms = new long[m];
      long[] gns = new long[n];
      gms[0] = 1;
      gns[0] = 1;
      gms[1] = power(G, (MO - 1) / m);
      gns[1] = power(G, (MO - 1) / n);
      for (int i = 2; i < m; ++i) {
        gms[i] = (gms[i - 1] * gms[1]) % MO;
      }
      for (int i = 2; i < n; ++i) {
        gns[i] = (gns[i - 1] * gns[1]) % MO;
      }
      
      long[][] f = new long[m][n];
      f[0][0] = f[1][0] = f[0][1] = f[m - 1][0] = f[0][n - 1] = 1;
      
      for (int x = 0; x < m; ++x) {
        fft(n, gns, f[x]);
      }
      for (int y = 0; y < n; ++y) {
        long[] work = new long[m];
        for (int x = 0; x < m; ++x) {
          work[x] = f[x][y];
        }
        fft(m, gms, work);
        for (int x = 0; x < m; ++x) {
          f[x][y] = work[x];
        }
      }
      
      // long TT = 1 + (T - 1) % (MO - 1);
      for (int x = 0; x < m; ++x) for (int y = 0; y < n; ++y) {
        // f[x][y] = power(f[x][y], TT);
        f[x][y] = power(f[x][y], T);
      }
      
      for (int i = 1; i < m - i; ++i) {
        long t = gms[i];
        gms[i] = gms[m - i];
        gms[m - i] = t;
      }
      for (int i = 1; i < n - i; ++i) {
        long t = gns[i];
        gns[i] = gns[n - i];
        gns[n - i] = t;
      }
      for (int x = 0; x < m; ++x) {
        fft(n, gns, f[x]);
      }
      for (int y = 0; y < n; ++y) {
        long[] work = new long[m];
        for (int x = 0; x < m; ++x) {
          work[x] = f[x][y];
        }
        fft(m, gms, work);
        for (int x = 0; x < m; ++x) {
          f[x][y] = work[x];
        }
      }
      long invMN = power((1L * m * n) % MO, MO - 2);
      for (int x = 0; x < m; ++x) for (int y = 0; y < n; ++y) {
        f[x][y] = (f[x][y] * invMN) % MO;
      }
      
      long ans = 0;
      for (int s : new int[]{+1, -1}) for (int t : new int[]{+1, -1}) {
        int dx = (s * C - A) & (m - 1);
        int dy = (t * D - B) & (n - 1);
        ans += s * t * f[dx][dy];
      }
      ans = (ans % MO + MO) % MO;
      System.out.println(ans);
    }
  }
  
  /*
  long power(long a, long e) {
    if (e == 0) {
      return 1 % MO;
    } else {
      long b = power(a, e / 2);
      b = (b * b) % MO;
      if (e % 2 != 0) {
        b = (b * a) % MO;
      }
      return b;
    }
  }
  //*/
  //*
  long power(long a, long e) {
    long b = 1 % MO;
    for (; e > 0; e /= 2) {
      if (e % 2 != 0) {
        b = (b * a) % MO;
      }
      a = (a * a) % MO;
    }
    return b;
  }
  //*/
  
  void fft(int n, long[] gs, long[] xs) {
    for (int l = n, shift = 0; (l /= 2) >= 1; ++shift) {
      for (int i = 0; i < l; ++i) {
        for (int j = i; j < n; j += l * 2) {
          long t = (xs[j] - xs[j + l]) % MO;
          xs[j] = (xs[j] + xs[j + l]) % MO;
          xs[j + l] = (gs[i << shift] * t) % MO;
        }
      }
    }
    for (int i = 0, j = 1; j < n; ++j) {
      for (int k = n / 2; k > (i ^= k); k /= 2) {}
      if (j < i) {
        long t = xs[i];
        xs[i] = xs[j];
        xs[j] = t;
      }
    }
  }
}
0