結果

問題 No.6 使いものにならないハッシュ
ユーザー Ai3ShotaAi3Shota
提出日時 2018-05-25 17:46:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 16 ms / 5,000 ms
コード長 1,037 bytes
コンパイル時間 1,215 ms
コンパイル使用メモリ 147,700 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-14 23:11:59
合計ジャッジ時間 2,864 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int N, K;
//vector<int> prime;
bool used[10];
int dp[10] = {0};

bool pdp[200000];
vector<int> Prime(){
	vector<int> ret;
	for (int i = 2; i < 200000; i++)
	{
		if (!pdp[i]){
    		ret.push_back(i);
    		for (int j = i + i; j < 200000; j += i)
    		{
    			pdp[j] = true;
    		}
		}
	}
	return ret;
}

int Hash(int num){
    int res = 0;
	while (num > 0){
		res += num % 10;
		num /= 10;
	}
	if (res >= 10) return Hash(res);
	return res;
}

int main(void){
    
    cin >> K >> N;
    
    auto prime = Prime();
    while(prime[0] < K) prime.erase(prime.begin());
    
    int j = 0, p_head = 0, p_len = 0;
    for(int i = 0; i < prime.size() && prime[i] <= N; ++i){
        int i_h = Hash(prime[i]);
        ++dp[i_h];
        while(dp[i_h] > 1){
            int j_h = Hash(prime[j++]);
            --dp[j_h];
        }
        if(i - j + 1 >= p_len){
            p_head = prime[j];
            p_len = i - j + 1;
        }
    }
    
    cout << p_head << endl;
    
    return 0;
}
0