結果
問題 |
No.2073 Concon Substrings (Swap Version)
|
ユーザー |
![]() |
提出日時 | 2022-09-20 12:30:23 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 173 ms / 2,000 ms |
コード長 | 1,756 bytes |
コンパイル時間 | 2,226 ms |
コンパイル使用メモリ | 77,848 KB |
実行使用メモリ | 42,584 KB |
最終ジャッジ日時 | 2024-12-22 03:30:25 |
合計ジャッジ時間 | 8,497 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 37 |
ソースコード
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); char[] inputs = sc.next().toCharArray(); int[] cCounts = new int[3]; int[] oCounts = new int[3]; int[] nCounts = new int[3]; for (int i = 0; i < n * 3; i++) { if (inputs[i] == 'c') { cCounts[i % 3]++; } else if (inputs[i] == 'o') { oCounts[i % 3]++; } else if (inputs[i] == 'n') { nCounts[i % 3]++; } } int ans = 0; int[] counts = new int[3]; for (int i = 0; i < 3; i++) { counts[i] = Math.min(cCounts[i], Math.min(oCounts[(i + 1) % 3], nCounts[(i + 2) % 3])); ans += counts[i]; } if (ans == n) { if (counts[0] != n) { ans--; } } System.out.println(ans); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); 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 { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }