結果
問題 | No.2017 Mod7 Parade |
ユーザー | tenten |
提出日時 | 2022-07-25 21:34:39 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 748 ms / 2,000 ms |
コード長 | 2,241 bytes |
コンパイル時間 | 2,147 ms |
コンパイル使用メモリ | 74,756 KB |
実行使用メモリ | 59,176 KB |
最終ジャッジ日時 | 2023-09-22 07:45:58 |
合計ジャッジ時間 | 14,003 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
49,548 KB |
testcase_01 | AC | 43 ms
49,672 KB |
testcase_02 | AC | 42 ms
47,428 KB |
testcase_03 | AC | 651 ms
58,748 KB |
testcase_04 | AC | 556 ms
58,800 KB |
testcase_05 | AC | 466 ms
59,176 KB |
testcase_06 | AC | 669 ms
58,792 KB |
testcase_07 | AC | 214 ms
57,204 KB |
testcase_08 | AC | 522 ms
58,556 KB |
testcase_09 | AC | 289 ms
57,824 KB |
testcase_10 | AC | 489 ms
58,740 KB |
testcase_11 | AC | 584 ms
58,824 KB |
testcase_12 | AC | 550 ms
58,912 KB |
testcase_13 | AC | 748 ms
58,700 KB |
testcase_14 | AC | 744 ms
58,900 KB |
testcase_15 | AC | 720 ms
58,792 KB |
testcase_16 | AC | 748 ms
58,644 KB |
testcase_17 | AC | 731 ms
58,728 KB |
testcase_18 | AC | 704 ms
58,876 KB |
testcase_19 | AC | 260 ms
58,372 KB |
testcase_20 | AC | 42 ms
49,388 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { static final int MOD = 1000000007; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int[] dp = new int[7]; for (int i = 1; i <= n; i++) { dp[0]++; int[] next = new int[7]; int x = sc.nextInt(); int length = sc.nextInt(); int mod = getMOD(x, length); int by = pow(10, length); for (int j = 0; j < 7; j++) { next[(j * by + mod) % 7] += dp[j]; next[(j * by + mod) % 7] %= MOD; } dp[0]--; for (int j = 0; j < 7; j++) { dp[j] += next[j]; dp[j] %= MOD; } } long ans = 0; for (int i = 0; i < 7; i++) { ans += (long)i * dp[i] % MOD; ans %= MOD; } System.out.println(ans); } static int getMOD(int x, int length) { if (length == 1) { return x % 7; } else if (length % 2 == 0) { int tmp = getMOD(x, length / 2); return (tmp * pow(10, length / 2) + tmp) % 7; } else { return (getMOD(x, length - 1) * 10 + x) % 7; } } static int pow(int x, int p) { if (p == 0) { return 1; } else if (p % 2 == 0) { return pow(x * x % 7, p / 2); } else { return pow(x, p - 1) * x % 7; } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); 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 String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }