結果
問題 | No.2017 Mod7 Parade |
ユーザー | tenten |
提出日時 | 2023-01-18 16:28:33 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,750 bytes |
コンパイル時間 | 2,640 ms |
コンパイル使用メモリ | 91,284 KB |
実行使用メモリ | 60,700 KB |
最終ジャッジ日時 | 2024-06-11 17:26:14 |
合計ジャッジ時間 | 34,256 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
37,152 KB |
testcase_01 | AC | 51 ms
37,240 KB |
testcase_02 | AC | 47 ms
37,048 KB |
testcase_03 | TLE | - |
testcase_04 | AC | 1,464 ms
49,084 KB |
testcase_05 | AC | 1,186 ms
49,508 KB |
testcase_06 | TLE | - |
testcase_07 | AC | 579 ms
47,528 KB |
testcase_08 | AC | 1,397 ms
50,328 KB |
testcase_09 | AC | 691 ms
48,952 KB |
testcase_10 | AC | 1,391 ms
50,416 KB |
testcase_11 | AC | 1,852 ms
60,700 KB |
testcase_12 | AC | 1,633 ms
48,980 KB |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | AC | 246 ms
50,528 KB |
testcase_20 | AC | 51 ms
36,888 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; 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[] counts = new int[7]; counts[0] = 1; for (int i = 0; i < n; i++) { int d = sc.nextInt() % 7; int length = sc.nextInt(); int[] tmp = new int[7]; for (int j = 0; j < 7; j++) { int next = j * pow(10, length) + fromLength(d, length); tmp[next % 7] += counts[j]; } for (int j = 0; j < 7; j++) { counts[j] += tmp[j]; counts[j] %= MOD; } } long ans = 0; for (int i = 1; i < 7; i++) { ans += counts[i] * (long)i; ans %= MOD; } System.out.println(ans); } static int fromLength(int d, int length) { if (length == 1) { return d % 7; } else if (length % 2 == 0) { int half = fromLength(d, length / 2); return (half * pow(10, length / 2) + half) % 7; } else { return (fromLength(d, length - 1) * 10 + d) % 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 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(); } }