結果
問題 | No.1171 Runs in Subsequences |
ユーザー |
![]() |
提出日時 | 2020-08-14 22:23:14 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 432 ms / 2,000 ms |
コード長 | 970 bytes |
コンパイル時間 | 4,180 ms |
コンパイル使用メモリ | 76,600 KB |
実行使用メモリ | 139,672 KB |
最終ジャッジ日時 | 2024-10-10 15:45:24 |
合計ジャッジ時間 | 6,906 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 |
ソースコード
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); char[] s = br.readLine().toCharArray(); br.close(); int mod = 1000000007; int n = s.length; long[][] dpn = new long[n + 1][26]; long[][] dpc = new long[n + 1][26]; for (int i = 0; i < n; i++) { int d = s[i] - 'a'; for (int j = 0; j < 26; j++) { if (j == d) { dpn[i + 1][j] += dpn[i][j] * 2 + 1; dpc[i + 1][j] += dpc[i][j] * 2 + 1; } else { dpn[i + 1][j] = dpn[i][j]; dpc[i + 1][j] = dpc[i][j]; dpn[i + 1][d] += dpn[i][j]; dpc[i + 1][d] += dpc[i][j] + dpn[i][j]; } } for (int j = 0; j < 26; j++) { dpn[i + 1][j] %= mod; dpc[i + 1][j] %= mod; } } long ans = 0; for (int j = 0; j < 26; j++) { ans += dpc[n][j]; } ans %= mod; System.out.println(ans); } }