結果

問題 No.2244 Integer Complete
ユーザー shobonvipshobonvip
提出日時 2023-03-08 05:00:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,367 bytes
コンパイル時間 4,458 ms
コンパイル使用メモリ 266,860 KB
実行使用メモリ 4,432 KB
最終ジャッジ日時 2023-10-18 05:48:38
合計ジャッジ時間 6,930 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 18 ms
4,432 KB
testcase_18 AC 18 ms
4,432 KB
testcase_19 AC 23 ms
4,432 KB
testcase_20 AC 51 ms
4,348 KB
testcase_21 AC 52 ms
4,348 KB
testcase_22 AC 29 ms
4,348 KB
testcase_23 AC 8 ms
4,348 KB
testcase_24 AC 47 ms
4,348 KB
testcase_25 AC 36 ms
4,348 KB
testcase_26 AC 13 ms
4,348 KB
testcase_27 AC 55 ms
4,432 KB
testcase_28 AC 26 ms
4,432 KB
testcase_29 AC 55 ms
4,432 KB
testcase_30 AC 49 ms
4,432 KB
testcase_31 AC 10 ms
4,348 KB
testcase_32 AC 9 ms
4,348 KB
testcase_33 AC 3 ms
4,348 KB
testcase_34 AC 14 ms
4,348 KB
testcase_35 AC 13 ms
4,348 KB
testcase_36 AC 14 ms
4,348 KB
testcase_37 AC 23 ms
4,348 KB
testcase_38 AC 15 ms
4,348 KB
testcase_39 AC 12 ms
4,348 KB
testcase_40 AC 10 ms
4,348 KB
testcase_41 AC 13 ms
4,348 KB
testcase_42 AC 13 ms
4,348 KB
testcase_43 AC 16 ms
4,348 KB
testcase_44 AC 13 ms
4,348 KB
testcase_45 AC 13 ms
4,348 KB
testcase_46 AC 20 ms
4,348 KB
testcase_47 AC 17 ms
4,348 KB
testcase_48 AC 12 ms
4,348 KB
testcase_49 AC 12 ms
4,348 KB
testcase_50 AC 12 ms
4,348 KB
testcase_51 AC 18 ms
4,348 KB
testcase_52 AC 18 ms
4,348 KB
testcase_53 AC 15 ms
4,348 KB
testcase_54 AC 16 ms
4,348 KB
testcase_55 AC 7 ms
4,348 KB
testcase_56 AC 7 ms
4,348 KB
testcase_57 AC 3 ms
4,348 KB
testcase_58 AC 13 ms
4,348 KB
testcase_59 AC 13 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;

typedef modint998244353 mint;
typedef long long ll;

// makediv
vector<ll> makediv(ll n){
	vector<ll> ld, ud;
	for (ll i=1; i*i<=n; i++){
		if (n%i == 0){
			ld.push_back(i);
			if (i != n/i){
				ud.push_back(n/i);
			}
		}
	}
	reverse(ud.begin(), ud.end());
	ld.insert(ld.end(), ud.begin(), ud.end());
	return ld;
}
// -----

int main(){
	int n,m; cin >> n >> m;
	vector<ll> a(n);
	vector<ll> a2(n);
	vector<ll> b(m);
	vector<ll> b2(m);
	for (int i=0; i<n; i++){
		cin >> a[i];
		a2[i] = a[i] * a[i];
	}
	for (int i=0; i<m; i++){
		cin >> b[i];
		b2[i] = b[i] * b[i];
	}

	if (a[0] != 1 || b[0] != 1){
		cout << 1 << endl;
		return 0;
	}

	vector<bool> c(40000);
	for (int i=0; i<n; i++){
		c[a[i]] = true;
	}
	for (int i=0; i<m; i++){
		c[b[i]] = true;
	}

	ll v = 0;
	for (int i=1; i<40000; i++){
		if (!c[i]){
			v = i * i;
			break;
		}
	}

	ll k = v;
	while (true){
		bool mode = false;
		for (ll i: makediv(k)){
			ll j = k / i;
			int x = upper_bound(a2.begin(),a2.end(),i) - a2.begin() - 1;
			int y = upper_bound(b2.begin(),b2.end(),j) - b2.begin() - 1;
			if (x < 0 || y < 0) continue;
			if ((a[x] + 1) * (a[x] + 1) <= i) continue;
			if ((b[y] + 1) * (b[y] + 1) <= j) continue;
			mode = true;
			break;
		}
		if (!mode) break;
		k++;
	}
	cout << k << endl;
}
0