結果

問題 No.346 チワワ数え上げ問題
ユーザー motimoti
提出日時 2018-05-26 01:22:08
言語 Perl
(5.38.2)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 416 bytes
コンパイル時間 44 ms
コンパイル使用メモリ 5,216 KB
実行使用メモリ 15,880 KB
最終ジャッジ日時 2023-09-11 03:34:09
合計ジャッジ時間 2,453 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,072 KB
testcase_01 AC 5 ms
4,832 KB
testcase_02 AC 5 ms
4,896 KB
testcase_03 AC 5 ms
5,032 KB
testcase_04 AC 6 ms
4,940 KB
testcase_05 AC 5 ms
4,904 KB
testcase_06 AC 5 ms
4,856 KB
testcase_07 AC 5 ms
4,832 KB
testcase_08 AC 5 ms
4,904 KB
testcase_09 AC 6 ms
4,988 KB
testcase_10 AC 75 ms
15,828 KB
testcase_11 AC 45 ms
11,428 KB
testcase_12 AC 60 ms
13,404 KB
testcase_13 AC 42 ms
10,596 KB
testcase_14 AC 8 ms
5,340 KB
testcase_15 AC 57 ms
12,604 KB
testcase_16 AC 63 ms
13,956 KB
testcase_17 AC 75 ms
15,720 KB
testcase_18 AC 76 ms
15,708 KB
testcase_19 AC 65 ms
14,132 KB
testcase_20 AC 87 ms
15,868 KB
testcase_21 AC 84 ms
15,812 KB
testcase_22 AC 84 ms
15,880 KB
testcase_23 AC 5 ms
5,084 KB
testcase_24 AC 5 ms
4,904 KB
testcase_25 AC 5 ms
4,904 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

use strict;
use warnings;

my $l = <>; chomp $l;
my @arr = split//,$l;

my @wcount;
push @wcount, 0;
for (my $i = 0; $i < @arr; $i++) {
  my $isw = $arr[$i] eq 'w' ? 1 : 0;
  push @wcount, $wcount[$i] + $isw;
}
my $maxw = $wcount[@wcount - 1];
my $ans = 0;
for (my $i = 0; $i < @arr; $i++) {
  my $right_wcnt = $maxw - $wcount[$i + 1];
  $ans += $right_wcnt * ($right_wcnt - 1) / 2 if $arr[$i] eq 'c';
}
print $ans;
0