結果
問題 |
No.3110 Like CPCTF?
|
ユーザー |
![]() |
提出日時 | 2025-04-18 20:30:29 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 152 ms / 2,000 ms |
コード長 | 1,101 bytes |
コンパイル時間 | 5,611 ms |
コンパイル使用メモリ | 79,408 KB |
実行使用メモリ | 56,556 KB |
最終ジャッジ日時 | 2025-04-18 20:30:39 |
合計ジャッジ時間 | 8,445 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 |
ソースコード
import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); char[] s = sc.next().toCharArray(); sc.close(); long ans = 0; long[][][][] dp = new long[5][26][26][26]; for (int i = 0; i < n; i++) { int c = s[i] - 'A'; for (int j = 0; j < 26; j++) { if (j == c) { continue; } for (int j2 = 0; j2 < 26; j2++) { if (j2 == c || j2 == j) { continue; } for (int j3 = 0; j3 < 26; j3++) { if (j3 == c || j3 == j || j3 == j2) { continue; } ans += dp[4][j][j2][j3]; } } } for (int j = 0; j < 26; j++) { for (int j2 = 0; j2 < 26; j2++) { if (j != j2 && j != c && j2 != c) { dp[4][j][j2][c] += dp[3][j][j2][0]; } } } for (int j2 = 0; j2 < 26; j2++) { if (j2 != c) { dp[3][c][j2][0] += dp[2][c][j2][0]; } } for (int j = 0; j < 26; j++) { if (j != c) { dp[2][j][c][0] += dp[1][j][0][0]; } } dp[1][c][0][0]++; } System.out.println(ans); } }