結果

問題 No.1597 Matrix Sort
ユーザー さかぽんさかぽん
提出日時 2021-07-11 00:01:42
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 471 ms / 1,500 ms
コード長 1,462 bytes
コンパイル時間 4,571 ms
コンパイル使用メモリ 111,916 KB
実行使用メモリ 51,332 KB
最終ジャッジ日時 2023-09-14 20:00:53
合計ジャッジ時間 13,630 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
21,744 KB
testcase_01 AC 71 ms
21,844 KB
testcase_02 AC 71 ms
19,720 KB
testcase_03 AC 453 ms
49,032 KB
testcase_04 AC 464 ms
51,332 KB
testcase_05 AC 467 ms
49,584 KB
testcase_06 AC 455 ms
51,076 KB
testcase_07 AC 471 ms
49,508 KB
testcase_08 AC 430 ms
51,124 KB
testcase_09 AC 436 ms
47,564 KB
testcase_10 AC 367 ms
47,372 KB
testcase_11 AC 346 ms
47,024 KB
testcase_12 AC 305 ms
42,440 KB
testcase_13 AC 388 ms
45,940 KB
testcase_14 AC 428 ms
47,148 KB
testcase_15 AC 286 ms
46,380 KB
testcase_16 AC 366 ms
45,612 KB
testcase_17 AC 403 ms
49,136 KB
testcase_18 AC 453 ms
47,072 KB
testcase_19 AC 406 ms
49,060 KB
testcase_20 AC 392 ms
48,980 KB
testcase_21 AC 383 ms
44,960 KB
testcase_22 AC 387 ms
46,416 KB
testcase_23 AC 373 ms
45,380 KB
testcase_24 AC 174 ms
37,496 KB
testcase_25 AC 175 ms
37,492 KB
testcase_26 AC 68 ms
21,848 KB
testcase_27 AC 68 ms
23,832 KB
testcase_28 AC 69 ms
23,860 KB
testcase_29 AC 70 ms
21,856 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

class G
{
	static int[] Read() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
	static (int, int) Read2() { var a = Read(); return (a[0], a[1]); }
	static long[] ReadL() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
	static (long, long, long) Read3L() { var a = ReadL(); return (a[0], a[1], a[2]); }
	static void Main() => Console.WriteLine(Solve());
	static object Solve()
	{
		var (n, k, p) = ((int, long, int))Read3L();
		var a = Read();
		var b = Read();

		Array.Sort(a);
		Array.Reverse(a);
		Array.Sort(b);
		b = b.Concat(b.Select(v => v + p)).Concat(b.Select(v => v + 2 * p)).ToArray();

		return First(0, p, x =>
		{
			// x までの個数
			var c = 0L;
			var l = new int[n];
			var r = new int[n];

			foreach (var (i, j) in TwoPointers(n, b.Length, (i, j) => a[i] + b[j] >= p))
				l[i] = j;
			foreach (var (i, j) in TwoPointers(n, b.Length, (i, j) => a[i] + b[j] > p + x))
				r[i] = j;

			for (int i = 0; i < n; i++)
				c += r[i] - l[i];
			return c >= k;
		});
	}

	static int First(int l, int r, Func<int, bool> f)
	{
		int m;
		while (l < r) if (f(m = l + (r - l - 1) / 2)) r = m; else l = m + 1;
		return r;
	}

	static IEnumerable<(int i, int j)> TwoPointers(int n1, int n2, Func<int, int, bool> predicate)
	{
		for (int i = 0, j = 0; i < n1 && j < n2; ++i)
			for (; j < n2; ++j)
				if (predicate(i, j)) { yield return (i, j); break; }
	}
}
0