結果
問題 | No.2017 Mod7 Parade |
ユーザー |
![]() |
提出日時 | 2023-01-18 16:28:33 |
言語 | Java (openjdk 23) |
結果 |
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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 TLE * 8 |
ソースコード
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();}}