結果
問題 | No.346 チワワ数え上げ問題 |
ユーザー | Grenache |
提出日時 | 2016-02-26 22:36:40 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 213 ms / 2,000 ms |
コード長 | 649 bytes |
コンパイル時間 | 3,525 ms |
コンパイル使用メモリ | 74,388 KB |
実行使用メモリ | 42,772 KB |
最終ジャッジ日時 | 2024-09-22 21:55:53 |
合計ジャッジ時間 | 9,122 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
import java.util.Scanner; public class Main_yukicoder346 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); char[] s = sc.next().toCharArray(); int n = s.length; int[] cnt = new int[n + 1]; for (int i = n - 1; i >= 0; i--) { cnt[i] = cnt[i + 1]; if (s[i] == 'w') { cnt[i]++; } } long ret = 0; for (int i = 0; i < n; i++) { if (s[i] == 'c' && cnt[i + 1] >= 2) { ret += (long)cnt[i + 1] * (cnt[i + 1] - 1) / 2; } } System.out.println(ret); sc.close(); } }