結果
問題 |
No.204 ゴールデン・ウィーク(2)
|
ユーザー |
![]() |
提出日時 | 2020-11-17 21:41:10 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 136 ms / 1,000 ms |
コード長 | 1,391 bytes |
コンパイル時間 | 2,539 ms |
コンパイル使用メモリ | 83,896 KB |
実行使用メモリ | 54,488 KB |
最終ジャッジ日時 | 2024-07-23 08:30:18 |
合計ジャッジ時間 | 10,691 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int d = sc.nextInt(); ArrayList<Integer> cal = new ArrayList<>(); char prev = 'x'; int count = 20; for (char c : (sc.next() + sc.next()).toCharArray()) { if (prev == c) { count++; } else { cal.add(count); count = 1; prev = c; } } if (prev == 'x') { cal.add(count + 20); } else { cal.add(count); cal.add(20); } if (cal.size() == 1) { System.out.println(d); return; } int max = d; for (int i = 0; i < cal.size(); i += 2) { if (i > 0 && i < cal.size() - 1) { if (d >= cal.get(i)) { max = Math.max(max, cal.get(i - 1) + cal.get(i) + cal.get(i + 1)); } else { max = Math.max(max, cal.get(i - 1) + d); max = Math.max(max, cal.get(i + 1) + d); } } else if (i == 0) { max = Math.max(max, cal.get(1) + d); } else { max = Math.max(max, cal.get(cal.size() - 2) + d); } } System.out.println(max); } }