結果

問題 No.607 開通777年記念
ユーザー Daigo HIROOKADaigo HIROOKA
提出日時 2018-06-06 00:13:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,228 ms / 2,000 ms
コード長 1,052 bytes
コンパイル時間 7,353 ms
コンパイル使用メモリ 74,104 KB
実行使用メモリ 53,984 KB
最終ジャッジ日時 2023-09-12 22:39:31
合計ジャッジ時間 8,853 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
39,288 KB
testcase_01 AC 116 ms
39,628 KB
testcase_02 AC 117 ms
39,812 KB
testcase_03 AC 114 ms
39,424 KB
testcase_04 AC 114 ms
39,512 KB
testcase_05 AC 113 ms
39,516 KB
testcase_06 AC 113 ms
39,384 KB
testcase_07 AC 630 ms
50,596 KB
testcase_08 AC 129 ms
39,356 KB
testcase_09 AC 238 ms
44,820 KB
testcase_10 AC 233 ms
44,224 KB
testcase_11 AC 1,228 ms
53,984 KB
testcase_12 AC 1,172 ms
53,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class No607{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int M = sc.nextInt();
		int[][] a = new int[M][N];
		for(int m = 0; m < M; m++){
			for(int n = 0; n < N; n++){
				if(m == 0){
					a[m][n] = sc.nextInt();	
				}else{
					a[m][n] = sc.nextInt() + a[m-1][n];
				}
			}
		}
		// System.out.println(Arrays.deepToString(a));
		System.out.println(is777(a)? "YES" : "NO");
	}

	private static boolean is777(int[][] passengers){
		
		for(int m = 0; m < passengers.length; m++){
			int num_passengers = passengers[m][0];
			int head = 1;
			int tail = 0;
			while(true){
				if(num_passengers < 777){
					if(head == passengers[0].length) break;
					num_passengers += passengers[m][head];
					head++;
				}else if(num_passengers > 777){
					if(tail == passengers[0].length) break;
					num_passengers -= passengers[m][tail];
					tail++;
				}else{
					return true;
				}
				// System.out.println(m + " " + num_passengers);
			}
		}
		return false;
	}
}
0