結果

問題 No.6 使いものにならないハッシュ
ユーザー cn_449cn_449
提出日時 2020-07-26 17:48:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 2,032 bytes
コンパイル時間 1,159 ms
コンパイル使用メモリ 117,768 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 23:26:08
合計ジャッジ時間 2,395 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,352 KB
testcase_01 AC 3 ms
4,352 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 3 ms
4,352 KB
testcase_04 AC 3 ms
4,352 KB
testcase_05 AC 3 ms
4,352 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 3 ms
4,352 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 3 ms
4,348 KB
testcase_13 AC 3 ms
4,352 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 3 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 4 ms
4,348 KB
testcase_21 AC 3 ms
4,352 KB
testcase_22 AC 4 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 4 ms
4,352 KB
testcase_25 AC 3 ms
4,348 KB
testcase_26 AC 3 ms
4,348 KB
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 3 ms
4,348 KB
testcase_29 AC 4 ms
4,352 KB
testcase_30 AC 3 ms
4,348 KB
testcase_31 AC 4 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#define debug(x) cerr << #x << ':' << x << '\n'
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

vector<bool> is_prime(200010, true);

void init() {
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i < 200010; i++) {
		if (is_prime[i]) {
			for (int j = 2 * i; j < 200010; j += i) {
				is_prime[j] = false;
			}
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	init();

	int k, n;
	cin >> k >> n;
	int len = 0; int ans = -1, st = -1;
	vector<bool> ap(9);
	deque<P> que;
	for (int i = k; i <= n; i++) {
		if (!is_prime[i]) continue;
		if (st == -1) st = i;
		int val = i % 9;
		if (ap[val]) {
			while (que.front().first != val) {
				P num = que.front(); ap[num.first] = false;
				que.pop_front();
			}
			que.pop_front();
			que.push_back({ val,i });
			st = que.front().second;
		}
		else que.push_back({ val,i });
		ap[val] = true;
		if (len == que.size() || chmax(len, que.size())) ans = st;
	}
	cout << ans << '\n';
}
0