結果
| 問題 |
No.346 チワワ数え上げ問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-06 18:00:02 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 108 ms / 2,000 ms |
| コード長 | 1,071 bytes |
| コンパイル時間 | 2,877 ms |
| コンパイル使用メモリ | 77,860 KB |
| 実行使用メモリ | 51,852 KB |
| 最終ジャッジ日時 | 2024-07-03 05:28:12 |
| 合計ジャッジ時間 | 6,157 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.function.*;
final class Solver {
void solve(Supplier<String> sc) {
var S = sc.get().toCharArray();
var cumOfW = new int[S.length];
for (int i = 1; i < cumOfW.length; i++) {
cumOfW[i] = cumOfW[i - 1] + (S[i] == 'w' ? 1 : 0);
}
long sumOfCWW = 0;
for (int i = 0; i < S.length; i++) {
if (S[i] != 'c') continue;
long trailingWs = cumOfW[S.length - 1] - cumOfW[i];
sumOfCWW += trailingWs * (trailingWs - 1) / 2;
}
System.out.println(sumOfCWW);
}
}
class Main {
public static void main(String... args) {
System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
var reader = new BufferedReader(new InputStreamReader(System.in));
new Solver().solve(new Supplier<>() {
StringTokenizer line;
public String get() {
while (line == null || !line.hasMoreTokens()) try {
line = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return line.nextToken();
}
});
System.out.flush();
}
}