結果
| 問題 |
No.1996 <><
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2022-07-26 12:46:04 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,367 bytes |
| コンパイル時間 | 2,937 ms |
| コンパイル使用メモリ | 80,756 KB |
| 実行使用メモリ | 308,680 KB |
| 最終ジャッジ日時 | 2024-07-16 05:28:17 |
| 合計ジャッジ時間 | 8,273 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 TLE * 1 -- * 21 |
ソースコード
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();
}
}
tenten