結果

問題 No.97 最大の値を求めるくえり
ユーザー latte0119latte0119
提出日時 2016-05-25 01:02:20
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 336 ms / 5,000 ms
コード長 1,730 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 80,876 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 12:26:37
合計ジャッジ時間 3,243 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
5,248 KB
testcase_01 AC 10 ms
5,376 KB
testcase_02 AC 73 ms
5,376 KB
testcase_03 AC 336 ms
5,376 KB
testcase_04 AC 29 ms
5,376 KB
testcase_05 AC 30 ms
5,376 KB
testcase_06 AC 31 ms
5,376 KB
testcase_07 AC 39 ms
5,376 KB
testcase_08 AC 50 ms
5,376 KB
testcase_09 AC 70 ms
5,376 KB
testcase_10 AC 110 ms
5,376 KB
testcase_11 AC 67 ms
5,376 KB
testcase_12 AC 58 ms
5,376 KB
testcase_13 AC 54 ms
5,376 KB
testcase_14 AC 46 ms
5,376 KB
testcase_15 AC 39 ms
5,376 KB
testcase_16 AC 37 ms
5,376 KB
testcase_17 AC 35 ms
5,376 KB
testcase_18 AC 35 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:57:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   57 |         scanf("%d%d", &N, &Q);
      |         ~~~~~^~~~~~~~~~~~~~~~
main.cpp:62:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   62 |                         scanf("%d", &q);
      |                         ~~~~~^~~~~~~~~~
main.cpp:73:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   73 |                         scanf("%d", &q);
      |                         ~~~~~^~~~~~~~~~

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<cstdio>
#include<algorithm>
#include<vector>
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
#include<map>
#include<set>
#include<sstream>
#include<bitset>
#include<numeric>
#include<climits>
#include<complex>
using namespace std;

typedef long long ll;

template<typename A,typename B>inline void chmin(A &a, B b) { if (a > b)a = b; }
template<typename A,typename B>inline void chmax(A &a, B b) { if (a < b)a = b; }

unsigned xor128_x = 123456789, xor128_y = 362436069, xor128_z = 521288629, xor128_w = 88675123;
unsigned xor128() {
	unsigned t = xor128_x ^ (xor128_x << 11);
	xor128_x = xor128_y; xor128_y = xor128_z; xor128_z = xor128_w;
	return xor128_w = xor128_w ^ (xor128_w >> 19) ^ (t ^ (t >> 8));
}
void generateA(int N, int A[]) {
	for (int i = 0; i < N; ++i)
		A[i] = xor128() % 100003;
}

const int mod = 100003;

ll modpow(ll n, int m) {
	ll ret = 1;
	while (m) {
		if (m & 1)ret = ret*n%mod;
		n = n*n%mod;
		m >>= 1;
	}
	return ret;
}

int N, Q;
int A[100003];

ll inv[100003];
bool is_exist[100003];

int main() {
	for (int i = 1; i < 100003; i++)inv[i] = modpow(i, mod - 2);

	scanf("%d%d", &N, &Q);
	generateA(N, A);
	if (N <= 450) {
		while (Q--) {
			int q;
			scanf("%d", &q);
			int ans = 0;
			for (int i = 0; i < N; i++)chmax(ans, (ll)A[i] * q%mod);
			printf("%d\n", ans);
		}
	}
	else{
		for (int i = 0; i < N; i++)is_exist[A[i]] = true;

		while (Q--) {
			int q;
			scanf("%d", &q);
			if (q == 0) {
				puts("0");
				continue;
			}
			for (int i = mod - 1; i >= 0; i--) {
				int qq = (ll)i*inv[q] % mod;
				if (is_exist[qq]) {
					printf("%d\n", i);
					break;
				}
			}
		}
	}
	return 0;
}
0