結果
| 問題 | No.1908 Assault for Keys | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2022-05-28 15:23:51 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,670 bytes | 
| コンパイル時間 | 2,965 ms | 
| コンパイル使用メモリ | 77,328 KB | 
| 実行使用メモリ | 60,796 KB | 
| 最終ジャッジ日時 | 2024-09-20 22:22:06 | 
| 合計ジャッジ時間 | 13,018 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 WA * 1 | 
| other | AC * 2 WA * 16 | 
ソースコード
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);
	}
}
            
            
            
        