結果

問題 No.559 swapAB列
ユーザー YamaKasaYamaKasa
提出日時 2018-06-05 03:09:29
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 714 bytes
コンパイル時間 2,520 ms
コンパイル使用メモリ 71,512 KB
実行使用メモリ 57,700 KB
最終ジャッジ日時 2023-09-12 22:21:39
合計ジャッジ時間 4,809 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
55,612 KB
testcase_01 AC 118 ms
55,640 KB
testcase_02 AC 117 ms
55,872 KB
testcase_03 AC 120 ms
55,952 KB
testcase_04 AC 119 ms
56,068 KB
testcase_05 AC 120 ms
57,700 KB
testcase_06 AC 123 ms
55,624 KB
testcase_07 WA -
testcase_08 AC 118 ms
55,620 KB
testcase_09 AC 118 ms
55,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		scan.close();
		int l = S.length();
		int cnt1 = 0;
		//int cnt2 = 0;
		for(int i = 0; i < l; i++) {
			char c = S.charAt(i);
			if(c == 'A') {
				cnt1 ++;
			}
		}
		//cnt2 = l - cnt1;
		if(l == 1) {
			System.out.println(0);
			System.exit(0);
		}
		int k = l - 1;
		int sum = 0;
		for(int i = cnt1 - 1; i >= 0; i--) {
			char c = S.charAt(i);
			if(c == 'B') {
				for(int j = k; j >= cnt1 - 1; j --) {
					char c2 = S.charAt(j);
					if(c2 == 'A') {
						k --;
						sum += j - i;
						break;
					}
				}
			}
		}
		System.out.println(sum);

	}
}
0