結果

問題 No.559 swapAB列
ユーザー fal_rndfal_rnd
提出日時 2017-08-25 22:26:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 2,198 ms
コンパイル使用メモリ 81,232 KB
実行使用メモリ 54,408 KB
最終ジャッジ日時 2024-04-23 15:32:23
合計ジャッジ時間 4,084 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
53,732 KB
testcase_01 AC 125 ms
54,408 KB
testcase_02 AC 124 ms
53,704 KB
testcase_03 AC 127 ms
54,120 KB
testcase_04 AC 125 ms
54,200 KB
testcase_05 AC 124 ms
53,840 KB
testcase_06 AC 125 ms
54,112 KB
testcase_07 AC 122 ms
54,116 KB
testcase_08 AC 124 ms
53,876 KB
testcase_09 AC 123 ms
53,860 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