結果

問題 No.239 にゃんぱすー
ユーザー YamaKasa
提出日時 2018-05-01 02:06:55
言語 Java
(openjdk 23)
結果
AC  
実行時間 225 ms / 2,000 ms
コード長 820 bytes
コンパイル時間 2,449 ms
コンパイル使用メモリ 77,432 KB
実行使用メモリ 46,444 KB
最終ジャッジ日時 2024-06-28 00:01:49
合計ジャッジ時間 10,226 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();

		String temp = "";
		int [][] B = new int[N][N];

		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N; j++) {
				temp = scan.next();
				if(temp.equals("nyanpass")) {
					B[i][j] = 1;
				}else {
					B[i][j] = 0;
				}
			}
		}
		scan.close();
		int []cnt = new int[N];
		Arrays.fill(cnt, 0);
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N; j++) {
				if(B[j][i] == 1) {
					cnt[i] ++;
				}
			}
		}
		int k = 0;
		int ans = 0;
		for(int i = 0; i < N; i++) {
			if(cnt[i] == N - 1) {
				ans = i + 1;
				k ++;
			}
		}
		if(k > 1 || k == 0) {
			System.out.println("-1");
		}else {
			System.out.println(ans);
		}


	}
}
0