結果

問題 No.2119 一般化百五減算
ユーザー 👑 ygussanyygussany
提出日時 2022-11-04 21:43:33
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 937 bytes
コンパイル時間 1,030 ms
コンパイル使用メモリ 29,392 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 00:02:42
合計ジャッジ時間 1,822 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 0 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 0 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 0 ms
4,380 KB
testcase_11 AC 0 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 0 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 0 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 0 ms
4,380 KB
testcase_20 AC 26 ms
4,376 KB
testcase_21 AC 26 ms
4,380 KB
testcase_22 AC 36 ms
4,376 KB
testcase_23 AC 34 ms
4,376 KB
testcase_24 AC 37 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

typedef struct {
	int key, id;
} data;

void merge_sort(int n, data x[])
{
	static data y[100001] = {};
	if (n <= 1) return;
	merge_sort(n / 2, &(x[0]));
	merge_sort((n + 1) / 2, &(x[n/2]));
	
	int i, p, q;
	for (i = 0, p = 0, q = n / 2; i < n; i++) {
		if (p >= n / 2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, M, B[100001], C[100001];
	data d[100001];
	scanf("%d", &N);
	scanf("%d", &M);
	for (i = 0; i < M; i++) {
		scanf("%d %d", &(B[i]), &(C[i]));
		d[i].key = B[i];
		d[i].id = i;
		C[i] = (C[i] % B[i] + B[i]) % B[i];
	}
	merge_sort(M, d);
	
	int j;
	for (i = C[d[M-1].id]; i <= N; i += B[d[M-1].id]) {
		for (j = M - 2; j >= 0; j--) if (i % B[d[j].id] != C[d[j].id]) break;
		if (j < 0) break;
	}
	if (i <= N) printf("%d\n", i);
	else printf("NaN\n");
	fflush(stdout);
	return 0;
}
0