結果

問題 No.1908 Assault for Keys
ユーザー eagleeagle
提出日時 2022-05-28 15:23:51
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,670 bytes
コンパイル時間 2,178 ms
コンパイル使用メモリ 77,532 KB
実行使用メモリ 62,188 KB
最終ジャッジ日時 2023-10-20 23:10:19
合計ジャッジ時間 12,627 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
57,156 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 136 ms
57,456 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 379 ms
60,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//看守の人数
		int N = sc.nextInt();
		//鍵の種類
		int M = sc.nextInt();
		//各看守が持っている鍵の状態
		String[] S = new String[N];
		for(int i = 0; i < N; i++) {
			S[i] = sc.next();
		}
		//襲った看守の人数
		int attack = 0;
		//集まった鍵の数
		int key = 0;
		//所持している鍵の種類
		int[] have = new int[M];
		//生き残っている看守
		int[] alive = new int[N];
		//全ての鍵を所持するまで繰返し
		while(key != M) {
			//どの看守を襲うかを決める
			int get = 0; //手に入る鍵の個数
			int index = -1; //襲う看守
			for(int i = 0; i < N; i++) {
				//襲った看守は対象外
				if(alive[i] == 1) {
					continue;
				}
				int cnt = 0; //持っていない鍵をカウント
				for(int j = 0; j < M; j++) {
					//鍵の所持状態を取り出す
					char c = S[i].charAt(j);
					//持っていない鍵を所持しているなら
					if(c == 'o' && have[j] == 0) {
						//カウントする
						cnt++;
					}
				}
				//手に入る最大数の更新処理
				if(get < cnt) {
					get = cnt;
					index = i;
				}
			}
			//看守を襲う
			for(int i = 0; i < M; i++) {
				//所持している鍵を獲得する
				if(S[index].charAt(i) == 'o' && have[i] == 0) {
					have[i] = 1;
				}
			}
			//鍵の個数を更新
			key += get;
			//襲った人数を加算
			attack++;
			//襲ったことを記憶する
			alive[index] = 1;
		}
		System.out.println(attack);
	}
}
0