結果

問題 No.1996 <><
ユーザー tentententen
提出日時 2022-07-26 12:46:04
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,367 bytes
コンパイル時間 3,326 ms
コンパイル使用メモリ 97,908 KB
実行使用メモリ 340,152 KB
最終ジャッジ日時 2023-09-23 05:29:02
合計ジャッジ時間 9,538 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
54,700 KB
testcase_01 AC 50 ms
50,124 KB
testcase_02 AC 55 ms
50,936 KB
testcase_03 AC 71 ms
53,176 KB
testcase_04 AC 53 ms
49,872 KB
testcase_05 AC 51 ms
50,072 KB
testcase_06 AC 69 ms
51,116 KB
testcase_07 AC 52 ms
49,812 KB
testcase_08 AC 65 ms
52,036 KB
testcase_09 AC 90 ms
53,112 KB
testcase_10 AC 87 ms
53,184 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static final int MOD = 1000000007;
    static ArrayList<HashMap<Integer, HashMap<Integer, Integer>>> dp = new ArrayList<>();
    static int[] values;
    static boolean[] isLower;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int k = sc.nextInt();
        values = new int[n];
        for (int i = 0; i < n; i++) {
            values[i] = sc.nextInt();
        }
        char[] string = (sc.next() + "<").toCharArray();
        isLower = new boolean[k + 1];
        for (int i = 0; i <= k; i++) {
            isLower[i] = (string[i] == '<');
            dp.add(new HashMap<>());
        }
        System.out.println(dfw(k, n - 1, Integer.MAX_VALUE));
    }
    
    static int dfw(int idx, int count, int v) {
        if (count < idx) {
            return 0;
        }
        if (idx < 0) {
            return 1;
        }
        if (!dp.get(idx).containsKey(count)) {
            dp.get(idx).put(count, new HashMap<>());
        }
        if (!dp.get(idx).get(count).containsKey(v)) {
            int ans = dfw(idx, count - 1, v);
            if (isLower[idx]) {
                if (values[count] < v) {
                    ans += dfw(idx - 1, count - 1, values[count]);
                    ans %= MOD;
                }
            } else {
                if (values[count] > v) {
                    ans += dfw(idx - 1, count - 1, values[count]);
                    ans %= MOD;
                }
            }
            dp.get(idx).get(count).put(v, ans);
        }
        return dp.get(idx).get(count).get(v);
    }
}
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();
    }
}
0