結果

問題 No.97 最大の値を求めるくえり
ユーザー bal4ubal4u
提出日時 2019-08-18 04:12:41
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 103 ms / 5,000 ms
コード長 1,538 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 32,384 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-08 17:01:12
合計ジャッジ時間 3,211 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,676 KB
testcase_01 AC 3 ms
6,676 KB
testcase_02 AC 102 ms
6,676 KB
testcase_03 AC 103 ms
6,676 KB
testcase_04 AC 8 ms
6,676 KB
testcase_05 AC 8 ms
6,676 KB
testcase_06 AC 9 ms
6,676 KB
testcase_07 AC 16 ms
6,676 KB
testcase_08 AC 27 ms
6,676 KB
testcase_09 AC 47 ms
6,676 KB
testcase_10 AC 84 ms
6,676 KB
testcase_11 AC 41 ms
6,676 KB
testcase_12 AC 35 ms
6,676 KB
testcase_13 AC 29 ms
6,676 KB
testcase_14 AC 20 ms
6,676 KB
testcase_15 AC 14 ms
6,676 KB
testcase_16 AC 13 ms
6,676 KB
testcase_17 AC 12 ms
6,676 KB
testcase_18 AC 11 ms
6,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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:27:21: note: in expansion of macro 'pc'
   27 |         while (i--) pc(b[i]);
      |                     ^~

ソースコード

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];

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

static 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+5] = {1,1};
int a[MAX+5]; int N;
char f[MAX+5];

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

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

	N = in(), Q = in();

	if (N <= 500) {
		generateA();
		while (Q--) {
			q = in();
			if (q == 0) pc('0');
            else {
				ans = 0, i = N; while (i--) {
					int t = (ll)q*a[i] % M;
					if (t > ans) ans = t;
				}
				out(ans);
			}
			pc('\n');
        }
	} else {
		generateB();
		while (Q--) {
			q = in();
			if (q == 0) pc('0');
			else {
				for (i = M-1; !f[i*(ll)inv[q] % M]; i--);
				out(i);
			}
			pc('\n');
		}
	}
	return 0;
}
0