結果

問題 No.97 最大の値を求めるくえり
ユーザー bal4ubal4u
提出日時 2019-05-06 22:10:43
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,588 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 30,780 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-10 21:26:30
合計ジャッジ時間 2,730 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 8 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:8:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:16:24: 備考: in expansion of macro ‘gc’
   16 |         int n = 0, c = gc();
      |                        ^~
main.c: 関数 ‘out’ 内:
main.c:9:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    9 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:26:17: 備考: in expansion of macro ‘pc’
   26 |         if (!n) pc('0');
      |                 ^~

ソースコード

diff #

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

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

#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]);
	}
}

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];
int a[MAX+10]; int N;

void generateA() {
	int i = N; while (i--) a[i] = (int)(xor128() % M);
}

int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; }

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

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

	N = in(), Q = in();
	generateA();
	qsort(a, N, sizeof(int), cmp);
	
	while (Q--) {
		q = in();
		if (q == 0) pc('0');
		else out((q * (long long)bsch(((M-1) * (long long)inv[q]) % M)) % M);
		pc('\n');
	}
	return 0;
}
0