結果

問題 No.1619 Coccinellidae
ユーザー ks2mks2m
提出日時 2021-07-22 21:54:30
言語 Java21
(openjdk 21)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 1,148 bytes
コンパイル時間 4,673 ms
コンパイル使用メモリ 74,620 KB
実行使用メモリ 61,124 KB
最終ジャッジ日時 2023-09-24 16:40:24
合計ジャッジ時間 8,423 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,308 KB
testcase_01 AC 244 ms
58,116 KB
testcase_02 AC 250 ms
61,056 KB
testcase_03 AC 125 ms
55,600 KB
testcase_04 AC 250 ms
61,100 KB
testcase_05 AC 221 ms
56,196 KB
testcase_06 AC 127 ms
55,656 KB
testcase_07 AC 215 ms
58,200 KB
testcase_08 AC 220 ms
58,652 KB
testcase_09 AC 127 ms
55,448 KB
testcase_10 AC 218 ms
58,116 KB
testcase_11 AC 231 ms
58,380 KB
testcase_12 AC 125 ms
55,868 KB
testcase_13 AC 247 ms
61,124 KB
testcase_14 AC 255 ms
60,644 KB
testcase_15 AC 127 ms
55,664 KB
testcase_16 AC 127 ms
53,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long m = sc.nextLong();
		long k = sc.nextLong();
		sc.close();

		long last = m - (long) (n - 1) * (n - 2) / 2;
		if (k == 0) {
			PrintWriter pw = new PrintWriter(System.out);
			for (int i = 0; i < n - 1; i++) {
				pw.println(i);
			}
			pw.println(last);
			pw.flush();
			return;
		}

		long sum = 0;
		int s = 0;
		int x = 0;
		for (int i = 1; i < n; i++) {
			sum += n - i;
			if (sum >= k) {
				s = i;
				sum -= n - i;
				x = (int) (k - sum);
				break;
			}
		}
		List<Integer> list = new ArrayList<>();
		int cnt = 0;
		for (int i = s; i < n; i++) {
			list.add(i);
			cnt++;
			if (cnt == x) {
				list.add(s - 1);
			}
		}
		for (int i = s - 2; i >= 0; i--) {
			list.add(i);
		}
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < n; i++) {
			if (list.get(i) == n - 1) {
				pw.println(last);
			} else {
				pw.println(list.get(i));
			}
		}
		pw.flush();
	}
}
0