結果
| 問題 |
No.2867 NOT FOUND 404 Again
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2024-09-02 13:42:52 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 1,501 ms / 3,000 ms |
| コード長 | 2,764 bytes |
| コンパイル時間 | 3,039 ms |
| コンパイル使用メモリ | 78,832 KB |
| 実行使用メモリ | 218,124 KB |
| 最終ジャッジ日時 | 2024-09-02 13:43:23 |
| 合計ジャッジ時間 | 30,289 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Main {
static final int MOD = 998244353;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
char[] num = sc.next().toCharArray();
int length = num.length;
if (length <= 2) {
System.out.println(num);
return;
}
int[] idxes = new int[]{1, 0, 0, 0, 2, 0, 0, 0, 0, 0};
int prepre = num[0] - '0';
int pre = num[1] - '0';
boolean has404 = false;
int[][][] dp = new int[length][3][3];
for (int i = 0; i < prepre * 10 + pre; i++) {
dp[1][idxes[i / 10]][idxes[i % 10]]++;
}
for (int i = 2; i < length; i++) {
int x = num[i] - '0';
for (int a = 0; a < 3; a++) {
for (int b = 0; b < 3; b++) {
for (int c = 0; c < 10; c++) {
if (a == 2 && b == 1 && c == 4) {
continue;
}
dp[i][b][idxes[c]] += dp[i - 1][a][b];
dp[i][b][idxes[c]] %= MOD;
}
}
}
if (has404) {
continue;
}
for (int j = 0; j < x; j++) {
if (prepre == 4 && pre == 0 && j == 4) {
continue;
}
dp[i][idxes[pre]][idxes[j]]++;
}
has404 = (prepre == 4 && pre == 0 && x == 4);
prepre = pre;
pre = x;
}
int ans = 0;
for (int[] arr : dp[length - 1]) {
for (int x : arr) {
ans += x;
ans %= MOD;
}
}
if (has404) {
ans--;
}
System.out.println(ans);
}
}
class Scanner {
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
StringBuilder sb = new StringBuilder();
public Scanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
} catch (Exception e) {
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String next() {
try {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
return st.nextToken();
}
}
}
tenten