結果

問題 No.6 使いものにならないハッシュ
ユーザー Shuz*Shuz*
提出日時 2019-07-24 15:28:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 5,000 ms
コード長 4,361 bytes
コンパイル時間 1,782 ms
コンパイル使用メモリ 177,032 KB
実行使用メモリ 5,076 KB
最終ジャッジ日時 2023-10-14 23:17:37
合計ジャッジ時間 3,933 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 56 ms
5,076 KB
testcase_03 AC 11 ms
4,352 KB
testcase_04 AC 13 ms
4,352 KB
testcase_05 AC 19 ms
4,368 KB
testcase_06 AC 30 ms
4,460 KB
testcase_07 AC 17 ms
4,352 KB
testcase_08 AC 25 ms
4,440 KB
testcase_09 AC 11 ms
4,524 KB
testcase_10 AC 2 ms
4,368 KB
testcase_11 AC 13 ms
4,352 KB
testcase_12 AC 39 ms
4,480 KB
testcase_13 AC 8 ms
4,352 KB
testcase_14 AC 11 ms
4,692 KB
testcase_15 AC 30 ms
4,348 KB
testcase_16 AC 19 ms
4,720 KB
testcase_17 AC 37 ms
4,976 KB
testcase_18 AC 52 ms
4,924 KB
testcase_19 AC 36 ms
4,960 KB
testcase_20 AC 34 ms
4,628 KB
testcase_21 AC 8 ms
4,352 KB
testcase_22 AC 36 ms
4,708 KB
testcase_23 AC 35 ms
4,512 KB
testcase_24 AC 34 ms
4,588 KB
testcase_25 AC 19 ms
4,352 KB
testcase_26 AC 41 ms
4,720 KB
testcase_27 AC 30 ms
4,700 KB
testcase_28 AC 22 ms
4,356 KB
testcase_29 AC 44 ms
4,844 KB
testcase_30 AC 41 ms
4,576 KB
testcase_31 AC 35 ms
4,672 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/istream:39,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/sstream:38,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/complex:45,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ccomplex:39,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:54,
         次から読み込み:  main.cpp:1:
メンバ関数 ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]’ 内,
    inlined from ‘int main()’ at main.cpp:141:13:
/usr/local/gcc7/include/c++/12.2.0/ostream:202:25: 警告: ‘res’ may be used uninitialized [-Wmaybe-uninitialized]
  202 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: 関数 ‘int main()’ 内:
main.cpp:123:8: 備考: ‘res’ はここで定義されています
  123 |     ll res, max = 0;
      |        ^~~

ソースコード

diff #

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

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
const ll inf = 1 << 30;
const ll LINF = LONG_MAX;
const ll INF = 1LL << 60;
const ull MAX = ULONG_MAX;
#define mp make_pair
#define pb push_back
#define elif else if
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run(a) __attribute__((constructor)) def _##a()
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define input(a) scanf("%lld", &(a))
#define print(a) printf("%lld\n", (a))
#define fi first
#define se second
#define ok(a, b) (0 <= (a) && (a) < (b))
template <class T> using vvector = vector<vector<T>>;
template <class T> using pvector = vector<pair<T, T>>;
template <class T>
using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;

template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

#define dump(a, h, w)                                                          \
    {                                                                          \
        cerr << __LINE__ << ": " << #a << " = [" << endl;                      \
        rep(__i, h) {                                                          \
            rep(__j, w) cerr << a[__i][__j] << space;                          \
            cerr << endl;                                                      \
        }                                                                      \
        cerr << "]" << endl;                                                   \
    }

#define vdump(a, n)                                                            \
    {                                                                          \
        cerr << __LINE__ << ": " << #a << " = [";                              \
        rep(__i, n) if (__i) cerr << space << a[__i];                          \
        else cerr << a[__i];                                                   \
        cerr << "]" << endl;                                                   \
    }

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define rep(i, n) for (ll i = 0, _##i = (n); i < _##i; ++i)
#define each(i, a) for (auto &&i : a)
#define loop() for (;;)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)
run(0) { fasten, fout(10); }

// Speed
#pragma GCC optimize("O3")
#pragma GCC target("avx")

// Math
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }
func sign(ll a) { return a ? abs(a) / a : 0; }

vector<ll> prime(ll n) {
    vector<ll> Prime(n + 1);
    rep(i, n + 1) Prime[i] = 1;
    Prime[0] = Prime[1] = 0;
    rep(i, n) {
        if (Prime[i]) {
            rep(j, n / i - 1) Prime[i * (j + 2)] = 0;
        }
    }
    return Prime;
}

ll Hash(ll n) {
    if (n < 10) return n;
    ll S = 0;
    while (n) S += n % 10, n /= 10;
    return Hash(S);
}

signed main() {
    ll N, K;
    cin >> K >> N;
    vector<ll> P = prime(N), Q;
    inc(i, K, N) if (P[i]) Q.pb(i);
    vdump(Q, Q.size());
    ll res, max = 0;
    rep(i, Q.size()) {
        map<ll, ll> M;
        rep(j, Q.size() - i) {
            if (M[Hash(Q[i + j])]++) {
                if (max <= j) {
                    max = j;
                    res = Q[i];
                }
                goto end;
            }
        }
        if (max <= Q.size() - i) {
            max = Q.size() - i;
            res = Q[i];
        }
    end:;
    }
    cout << res << endl;
}
0