結果

問題 No.893 お客様を誘導せよ
ユーザー ks2mks2m
提出日時 2019-09-27 21:35:43
言語 Java21
(openjdk 21)
結果
AC  
実行時間 279 ms / 2,000 ms
コード長 1,066 bytes
コンパイル時間 2,194 ms
コンパイル使用メモリ 78,552 KB
実行使用メモリ 61,724 KB
最終ジャッジ日時 2023-10-25 01:58:52
合計ジャッジ時間 4,634 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
52,256 KB
testcase_01 AC 53 ms
53,312 KB
testcase_02 AC 145 ms
58,028 KB
testcase_03 AC 211 ms
59,556 KB
testcase_04 AC 202 ms
59,544 KB
testcase_05 AC 203 ms
59,172 KB
testcase_06 AC 188 ms
59,212 KB
testcase_07 AC 53 ms
53,308 KB
testcase_08 AC 279 ms
61,724 KB
testcase_09 AC 83 ms
54,256 KB
testcase_10 AC 53 ms
53,320 KB
testcase_11 AC 76 ms
54,232 KB
testcase_12 AC 90 ms
54,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int cnt = 0;
		List<Queue<Integer>> list = new ArrayList<>(n);
		for (int i = 0; i < n; i++) {
			Queue<Integer> que = new ArrayDeque<>();
			list.add(que);
			String[] sa = br.readLine().split(" ");
			if (Integer.parseInt(sa[0]) == 0) {
				cnt++;
			}
			for (int j = 1; j < sa.length; j++) {
				que.add(Integer.parseInt(sa[j]));
			}
		}
		br.close();

		StringBuilder sb = new StringBuilder();
		while (cnt < n) {
			for (int i = 0; i < n; i++) {
				Queue<Integer> que = list.get(i);
				if (!que.isEmpty()) {
					sb.append(que.poll()).append(' ');
					if (que.isEmpty()) {
						cnt++;
					}
				}
			}
		}
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(sb.toString());
	}
}
0