結果

問題 No.596 郵便配達
ユーザー square1001square1001
提出日時 2017-11-10 23:00:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 654 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 41,472 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-03 13:10:59
合計ジャッジ時間 2,493 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 140 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 148 ms
5,376 KB
testcase_21 AC 145 ms
5,376 KB
testcase_22 AC 150 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int N, M, x, d, p;
int main() {
	scanf("%d %d", &N, &M);
	int al = N, ar = -1, bl = N, br = -1;
	for (int i = 0; i < M; i++) {
		scanf("%d %d", &x, &d);
		for (int j = 0; j < d; j++) {
			scanf("%d", &p);
			if (x > p) {
				al = min(al, p);
				ar = max(ar, x);
			}
			if(x < p) {
				bl = min(bl, x);
				br = max(br, p);
			}
		}
	}
	if (ar == -1 && br == -1) printf("0\n");
	else if (ar == -1) printf("%d\n", br - bl);
	else if (br == -1) printf("%d\n", ar - al);
	else printf("%d\n", min(ar + br - 2 * min(al, bl), 2 * max(ar, br) - al - bl));
	return 0;
}
0