結果

問題 No.559 swapAB列
ユーザー fal_rndfal_rnd
提出日時 2017-08-25 22:26:59
言語 Java19
(openjdk 21)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 2,906 ms
コンパイル使用メモリ 78,696 KB
実行使用メモリ 55,912 KB
最終ジャッジ日時 2023-08-05 18:49:15
合計ジャッジ時間 4,852 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
55,616 KB
testcase_01 AC 119 ms
55,660 KB
testcase_02 AC 118 ms
55,352 KB
testcase_03 AC 118 ms
55,792 KB
testcase_04 AC 119 ms
55,912 KB
testcase_05 AC 119 ms
55,708 KB
testcase_06 AC 119 ms
55,316 KB
testcase_07 AC 118 ms
55,616 KB
testcase_08 AC 120 ms
55,900 KB
testcase_09 AC 117 ms
55,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
	static IntStream INS(int n) {return REPS(n).map(i->getInt());}
	static Scanner s=new Scanner(System.in);
	static int getInt(){return Integer.parseInt(s.next());}

	public static void main(String[]$){
		int r=0,b=0;
		char[]c=s.next().toCharArray();
		int n=c.length;
		int[]a=new int[n];
		a[n-1]=c[n-1]=='A'?1:0;
		for(int i=n-2;i>=0;--i) {
			a[i]=a[i+1]+(c[i]=='A'?1:0);
		}
		for(int i=0;i<c.length;++i) {
			if(c[i]=='B')
				r+=a[i];
		}
		System.out.println(r);
	}
}
0