結果
問題 | No.2060 AND Sequence |
ユーザー | tenten |
提出日時 | 2023-07-25 09:47:36 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 55 ms / 2,000 ms |
コード長 | 2,701 bytes |
コンパイル時間 | 2,770 ms |
コンパイル使用メモリ | 97,100 KB |
実行使用メモリ | 37,208 KB |
最終ジャッジ日時 | 2024-10-02 04:18:10 |
合計ジャッジ時間 | 6,843 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 52 ms
36,952 KB |
testcase_01 | AC | 52 ms
37,208 KB |
testcase_02 | AC | 53 ms
37,044 KB |
testcase_03 | AC | 53 ms
37,184 KB |
testcase_04 | AC | 52 ms
37,052 KB |
testcase_05 | AC | 53 ms
36,888 KB |
testcase_06 | AC | 53 ms
36,972 KB |
testcase_07 | AC | 53 ms
36,784 KB |
testcase_08 | AC | 52 ms
36,884 KB |
testcase_09 | AC | 53 ms
37,088 KB |
testcase_10 | AC | 53 ms
36,780 KB |
testcase_11 | AC | 51 ms
36,936 KB |
testcase_12 | AC | 53 ms
37,184 KB |
testcase_13 | AC | 53 ms
37,044 KB |
testcase_14 | AC | 54 ms
37,044 KB |
testcase_15 | AC | 54 ms
36,792 KB |
testcase_16 | AC | 53 ms
37,096 KB |
testcase_17 | AC | 53 ms
36,968 KB |
testcase_18 | AC | 55 ms
36,988 KB |
testcase_19 | AC | 53 ms
37,176 KB |
testcase_20 | AC | 54 ms
37,124 KB |
testcase_21 | AC | 52 ms
37,000 KB |
testcase_22 | AC | 52 ms
36,900 KB |
testcase_23 | AC | 53 ms
36,976 KB |
testcase_24 | AC | 52 ms
36,896 KB |
testcase_25 | AC | 53 ms
37,116 KB |
testcase_26 | AC | 52 ms
36,964 KB |
testcase_27 | AC | 53 ms
37,008 KB |
testcase_28 | AC | 52 ms
37,044 KB |
testcase_29 | AC | 52 ms
36,892 KB |
testcase_30 | AC | 53 ms
37,200 KB |
testcase_31 | AC | 53 ms
36,968 KB |
testcase_32 | AC | 53 ms
36,788 KB |
testcase_33 | AC | 52 ms
36,896 KB |
testcase_34 | AC | 53 ms
36,964 KB |
testcase_35 | AC | 52 ms
37,016 KB |
testcase_36 | AC | 53 ms
37,076 KB |
testcase_37 | AC | 53 ms
37,116 KB |
testcase_38 | AC | 54 ms
36,960 KB |
testcase_39 | AC | 52 ms
36,976 KB |
testcase_40 | AC | 53 ms
36,784 KB |
testcase_41 | AC | 53 ms
36,872 KB |
testcase_42 | AC | 53 ms
36,904 KB |
testcase_43 | AC | 53 ms
36,636 KB |
testcase_44 | AC | 54 ms
36,976 KB |
testcase_45 | AC | 53 ms
36,780 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static final int MOD = 998244353; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); StringBuilder tmp = new StringBuilder(); while (m > 0) { tmp.append(m % 2); m >>= 1; } char[] values = new String(tmp.reverse()).toCharArray(); int length = values.length; int[][] dp = new int[length + 1][length + 1]; int count = 0; for (int i = 1; i <= length; i++) { for (int j = 0; j < length; j++) { dp[i][j + 1] += dp[i - 1][j]; dp[i][j + 1] %= MOD; dp[i][j] += dp[i - 1][j]; dp[i][j] %= MOD; } if (values[i - 1] == '1') { dp[i][count]++; dp[i][count] %= MOD; count++; } } dp[length][count]++; long ans = 0; for (int i = 0; i <= length; i++) { ans += pow(n, i) * dp[length][i] % MOD; ans %= MOD; } System.out.println(ans); } static long pow(long x, int p) { if (p == 0) { return 1; } else if (p % 2 == 0) { return pow(x * x % MOD, p / 2); } else { return pow(x, p - 1) * x % MOD; } } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }