結果

問題 No.6 使いものにならないハッシュ
ユーザー 小指が強い人小指が強い人
提出日時 2016-05-31 01:47:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 2,833 bytes
コンパイル時間 3,007 ms
コンパイル使用メモリ 172,192 KB
実行使用メモリ 8,528 KB
最終ジャッジ日時 2023-10-14 22:59:28
合計ジャッジ時間 2,814 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,380 KB
testcase_01 AC 3 ms
8,284 KB
testcase_02 AC 4 ms
8,376 KB
testcase_03 AC 3 ms
8,276 KB
testcase_04 AC 4 ms
8,360 KB
testcase_05 AC 4 ms
8,420 KB
testcase_06 AC 4 ms
8,412 KB
testcase_07 AC 4 ms
8,296 KB
testcase_08 AC 4 ms
8,376 KB
testcase_09 AC 4 ms
8,260 KB
testcase_10 AC 4 ms
8,364 KB
testcase_11 AC 4 ms
8,360 KB
testcase_12 AC 4 ms
8,436 KB
testcase_13 AC 3 ms
8,304 KB
testcase_14 AC 4 ms
8,232 KB
testcase_15 AC 5 ms
8,528 KB
testcase_16 AC 5 ms
8,336 KB
testcase_17 AC 4 ms
8,376 KB
testcase_18 AC 5 ms
8,348 KB
testcase_19 AC 5 ms
8,428 KB
testcase_20 AC 5 ms
8,484 KB
testcase_21 AC 4 ms
8,336 KB
testcase_22 AC 4 ms
8,376 KB
testcase_23 AC 4 ms
8,384 KB
testcase_24 AC 4 ms
8,360 KB
testcase_25 AC 3 ms
8,260 KB
testcase_26 AC 5 ms
8,340 KB
testcase_27 AC 4 ms
8,396 KB
testcase_28 AC 4 ms
8,312 KB
testcase_29 AC 4 ms
8,380 KB
testcase_30 AC 5 ms
8,340 KB
testcase_31 AC 4 ms
8,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;

#define REP(i, a, n) for(ll i = a; i < n; i++)
#define RREP(i, a, n) for(ll i = n-1; i >= a; i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007

template<class T> T read(){T a;cin >> a;return a;}
template<class T> void read(T& a){cin >> a;}
template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<class T> void write(T a){cout << a << endl;}
template<class T> void writes(vector<T> a, char* c = " "){cout << a[0];for(int i = 1; i < a.size(); i++)cout << c << a[i];cout << endl;;}
void write(double a){cout << fixed << setprecision(12) << a << endl;}
void write(long double a){cout << fixed << setprecision(12) << a << endl;}
template<class T> void warr(T a, int n, char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ll gcd(ll a, ll b){while(true){ll k = a % b;if(k == 0)return b;a = b;b = k;}}
ll comb(ll n, ll m){ll p=1;m=min(m,n-m);for(ll i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}

int x1,x2;

int prime(veci& v, int n) {
    bool p[5000001] = {1, 1};
    for(int i = 2; i <= n; i++) {
        if(p[i]) continue;
        if(i>=x1&&i<=x2)
            v.push_back(i);
        for(int j = i * 2; j <= n; j += i)
            p[j] = true;
    }
    return v.size();
}

int fh(int v){
    if(v<10)return v;
    int p=0;
    while(v>0){
        p+=v%10;
        v/=10;
    }
    return fh(p);
}

int main(void)
{
    cin>>x1>>x2;
    veci pv;
    int pm=prime(pv,x2);
    veci hv(pm);
    rep(i,pm){
        hv[i]=fh(pv[i]);
    }
    bool bl[10]={0};
    int le=0,rt=0;
    int res=0,length=0,max_l=0;
    while(true){
        while(rt<pm && !bl[hv[rt]]){
            bl[hv[rt]]=true;
            length++;
            rt++;
        }
        if(length>=max_l){
            max_l=length;
            res=pv[le];
        }
        if(rt>=pm)break;
        while(le<rt && bl[hv[rt]]){
            bl[hv[le]]=false;
            length--;
            le++;
        }
    }
    write(res);
    return 0;
}
0