結果

問題 No.2017 Mod7 Parade
ユーザー tentententen
提出日時 2023-04-27 09:09:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 676 ms / 2,000 ms
コード長 2,813 bytes
コンパイル時間 3,185 ms
コンパイル使用メモリ 95,796 KB
実行使用メモリ 50,460 KB
最終ジャッジ日時 2024-04-28 05:07:39
合計ジャッジ時間 13,535 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
37,204 KB
testcase_01 AC 43 ms
37,332 KB
testcase_02 AC 44 ms
37,072 KB
testcase_03 AC 599 ms
47,368 KB
testcase_04 AC 475 ms
47,152 KB
testcase_05 AC 458 ms
47,216 KB
testcase_06 AC 621 ms
46,868 KB
testcase_07 AC 209 ms
44,300 KB
testcase_08 AC 475 ms
47,092 KB
testcase_09 AC 275 ms
46,544 KB
testcase_10 AC 475 ms
47,296 KB
testcase_11 AC 518 ms
46,992 KB
testcase_12 AC 484 ms
46,848 KB
testcase_13 AC 643 ms
46,888 KB
testcase_14 AC 676 ms
46,960 KB
testcase_15 AC 670 ms
47,008 KB
testcase_16 AC 671 ms
46,804 KB
testcase_17 AC 644 ms
47,136 KB
testcase_18 AC 639 ms
46,864 KB
testcase_19 AC 212 ms
50,460 KB
testcase_20 AC 45 ms
36,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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[] dp = new int[7];
        while (n-- > 0) {
            int x = sc.nextInt() % 7;
            int length = sc.nextInt();
            int target = getLength(x, length);
            int[] current = new int[7];
            int base = pow(3, length);
            for (int i = 0; i < 7; i++) {
                current[(i * base + target) % 7] += dp[i];
                current[(i * base + target) % 7] %= MOD;
            }
            for (int i = 0; i < 7; i++) {
                dp[i] += current[i];
                dp[i] %= MOD;
            }
            dp[target]++;
        }
        long ans = 0;
        for (int i = 1; i < 7; i++) {
            ans += (long)dp[i] * i % MOD;
            ans %= MOD;
        }
        System.out.println(ans);
    }
    
    static int getLength(int x, int length) {
        if (length == 1) {
            return x;
        } else if (length % 2 == 0) {
            int tmp = getLength(x, length / 2);
            return (tmp * pow(3, length / 2) + tmp) % 7;
        } else {
            return (getLength(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 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();
    }
    
}
0