結果
問題 | No.346 チワワ数え上げ問題 |
ユーザー | yun_app |
提出日時 | 2016-05-09 19:39:33 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 83 ms / 2,000 ms |
コード長 | 966 bytes |
コンパイル時間 | 2,540 ms |
コンパイル使用メモリ | 75,280 KB |
実行使用メモリ | 53,364 KB |
最終ジャッジ日時 | 2024-10-05 13:09:36 |
合計ジャッジ時間 | 4,773 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ class Ideone { public static void main (String[] args) throws java.lang.Exception { // your code goes here BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = br.readLine(); ArrayList<Long> w_num = new ArrayList<Long>(); long w_cnt = 0; for(int i=line.length()-1;i>=0;i--){ char c = line.charAt(i); if(c == 'c'){ w_num.add(w_cnt); }else if(c == 'w'){ w_cnt++; } } long ans = 0; for(long w:w_num){ ans += combination(w); } System.out.println(ans); } public static long combination(long n){ return (n * (n-1)) / 2; } }