結果

問題 No.6 使いものにならないハッシュ
ユーザー ry0u_ydry0u_yd
提出日時 2015-10-01 23:48:37
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,577 bytes
コンパイル時間 937 ms
コンパイル使用メモリ 83,100 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-27 01:21:22
合計ジャッジ時間 1,933 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <cmath>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

bool prime[10000000];
void Eratosthenes(int n) {
    rep(i,n) prime[i] = true;
    prime[1] = false;

    REP(i,2,(int)sqrt(n)) {
        if(prime[i]) {
            for(int j=0;i*(j+2)<=n-1;j++) {
                prime[i*(j+2)] = 0;
            }
        }
    }
}

int func(int x) {
    int ret = x;

    while(ret >= 10) {
        ret = 0;
        while(x != 0) {
            ret += x % 10;
            x /= 10;
        }

        x = ret;
    }

    return ret;
}

int main() {
    int k,n;
    cin >> k >> n;

    Eratosthenes(n+1);

    vector<int> v;
    REP(i,k,n+1) {
        if(prime[i]) v.push_back(i);
    }

    vector<int> res(v.size());
    rep(i,v.size()) {
        res[i] = func(v[i]);
    }

    int a = 0,b = 0;
    map<int,int> m;
    bool used[200005];
    memset(used,0,sizeof(used));

    rep(i,v.size()) {
        if(!used[res[i]]) {
            used[res[i]] = true;
            m[i-a] = max(m[i-a], v[a]);
        } else {
            while(used[res[i]]) {
                used[res[a]] = false;
                a++;
            }

            used[res[i]] = true;
            m[i-a] = max(m[i-a], v[a]);
        }
    }
    
    cout << m.rbegin()->second << endl;

    return 0;
}
0