結果

問題 No.97 最大の値を求めるくえり
ユーザー bal4ubal4u
提出日時 2019-08-17 20:29:15
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,536 bytes
コンパイル時間 432 ms
コンパイル使用メモリ 31,272 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 08:58:42
合計ジャッジ時間 10,166 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,348 KB
testcase_01 AC 16 ms
4,348 KB
testcase_02 WA -
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:10:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
   10 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:18:24: note: in expansion of macro 'gc'
   18 |         int n = 0, c = gc();
      |                        ^~
main.c: In function 'out':
main.c:11:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
   11 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:26:17: note: in expansion of macro 'pc'
   26 |         if (!n) pc('0');
      |                 ^~

ソースコード

diff #

// yukicoder: 97 最大の値を求めるくえり
// 2019.8.17 bal4u

#include <stdio.h>
#include <stdlib.h>

typedef long long ll;

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in() { // 整数の入力
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n) { // 非負整数の表示(出力)
	int i; char b[20];

	if (!n) pc('0');
	else {
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

unsigned x = 123456789, y = 362436069, z = 521288629, w = 88675123;
unsigned xor128() {
	unsigned t = x ^ (x << 11);
	x = y, y = z, z = w;
	return w = w ^ (w >> 19) ^ (t ^ (t >> 8));
}

#define M 100003
#define MAX M
int inv[MAX+10] = {1,1};
int a[MAX+10]; int N;

int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; }
void generateA() {
	int i = N; while (i--) a[i] = (int)(xor128() % M);
	qsort(a, N, sizeof(int), cmp);
}

int bs(int x) {
	int m, l = 0, r = N-1;
    while (l < r) {
        m = (l + r) >> 1;
		if (a[m] == x) return 1;
        if (a[m] < x) l = m + 1; else r = m;
    }
	return a[l] == x;
}

int main()
{
	int i, Q, q, t;
	
	for (i = 2; i <= MAX; i++) inv[i] = -(M/i)*(ll)inv[M % i] % M;

	N = in(), Q = in();
	generateA();
	
	while (Q--) {
		q = in();
		if (q == 0) { pc('0'); continue; }
		for (i = M-1; ; i--) {
			t = i * (ll)inv[q] % M;
			if (t < 0) t += M;
			if (bs(t)) { out(i); break; }
		}
	}
	return 0;
}
0