結果
問題 | No.346 チワワ数え上げ問題 |
ユーザー |
![]() |
提出日時 | 2016-06-02 16:59:17 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 173 ms / 2,000 ms |
コード長 | 464 bytes |
コンパイル時間 | 2,358 ms |
コンパイル使用メモリ | 74,376 KB |
実行使用メモリ | 42,708 KB |
最終ジャッジ日時 | 2024-10-08 05:33:53 |
合計ジャッジ時間 | 6,735 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
import java.util.Scanner; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); System.out.println(solve(sc.next())); sc.close(); } public static long solve (String s) { long wcnt = 0, sum = 0; int len = s.length(); for (int i = len - 1; i >= 0; i--) { if (s.charAt(i) == 'w') { wcnt++; continue; } if (s.charAt(i) == 'c') sum += wcnt * (wcnt - 1) / 2; } return sum; } }