/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 24ms 16.852 MiB
#2 Accepted 109ms 20.336 MiB
#3 Accepted 194ms 20.707 MiB
#4 Accepted 1299ms 25.195 MiB
#5 Accepted 1298ms 25.094 MiB
#6 Accepted 1384ms 25.379 MiB
#7 Wrong Answer 27ms 16.562 MiB
#8 Accepted 276ms 25.246 MiB
#9 Accepted 185ms 25.008 MiB
#10 Accepted 202ms 20.676 MiB
#11 Accepted 295ms 25.18 MiB
#12 Accepted 325ms 25.262 MiB
#13 Accepted 1194ms 25.145 MiB
#14 Accepted 1075ms 25.176 MiB
#15 Accepted 1381ms 25.297 MiB
#16 Accepted 227ms 25.207 MiB
#17 Accepted 1375ms 25.387 MiB
#18 Accepted 244ms 25.266 MiB
#19 Accepted 308ms 24.863 MiB
#20 Accepted 63ms 21.332 MiB
#21 Accepted 323ms 25.309 MiB
#22 Accepted 305ms 25.203 MiB
#23 Accepted 1380ms 25.344 MiB
#24 Accepted 1269ms 25.246 MiB
#25 Accepted 1375ms 25.445 MiB
#26 Accepted 1344ms 25.289 MiB
#27 Accepted 1379ms 24.695 MiB

Code

// #pragma GCC optimize("O3,unroll-loops,Ofast")
// #pragma GCC target("avx2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define endl '\n'

using namespace std;
using pii = pair<int, int>;
using tup = tuple<int, int, int>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T> using ordered_set = tree<T, null_type,
                         less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int inf = 1e18;
const int mod = 1000000007;
const double eps = 1e-9;
const int N = 400005;

int mdiv[N], nxtp[N], prevp[N], mark[N];
vector<int> primes;

void preprocess() {
    for(int i=1; i<N; i++) 
        for(int j=i*2; j<N; j+=i)
            mdiv[j] = i;

    mark[0] = mark[1] = 1;
    for(int i=2; i<N; i++) {
        if(mark[i]) continue;
        primes.push_back(i);
        for(int j=i*i; j<N; j+=i)
            mark[j] = 1;
    }

    for(int i=0; i<primes.size()-1; i++) {
        nxtp[primes[i]] = primes[i+1];
        prevp[primes[i+1]] = primes[i];
    }

    prevp[2] = -inf;
    nxtp[primes.back()] = inf;
}

int dist[N][2], vis[N][2];

void solve(int tc) {
    int n, m, k;
    cin >> n >> m >> k;

    vis[n][0] = tc;
    dist[n][0] = 0;
    queue<pii> q;
    q.push({n, 0});

    int ans = 0;
    while(!q.empty()) {
        auto [u, p] = q.front();
        q.pop();
        if(dist[u][p] == k) break;

        int primes = 0;
        for(int d=1; d<=m; d++) {
            bool f = 0;
            for(int j=0; j<2; j++) {
                int i = u + d * (j ? 1 : -1);
                if(i == u or i < 2) continue;

                int nxt = i / mdiv[i];

                if(vis[nxt][!p] != tc) {
                    vis[nxt][!p] = tc;
                    dist[nxt][!p] = dist[u][p] + 1;
                    q.push({nxt, !p});
                }
                primes += (!mark[nxt]);
                // f |= (!mark[nxt]);
            }
            // if(primes > 3) break;
            // if(f) break;
        }
    }

    for(int i=2; i<N; i++) {
        if(mark[i]) continue;
        for(int j=0; j<2; j++) {
            if(vis[i][j] != tc) continue;
            int left = k - dist[i][j];
            // cout << i << ' ' << j << ' ' << left << endl;
            if(nxtp[i] - i <= m) {
                if(left % 2) ans = max(ans, nxtp[i]);
                else ans = max(ans, i);

                if(left > 1 and nxtp[nxtp[i]] - nxtp[i] <= m) {
                    if(left % 2 == 0)
                        ans = max(ans, nxtp[nxtp[i]]);
                }
            }
            if(i - prevp[i] <= m) {
                if(left % 2) ans = max(ans, prevp[i]);
                else ans = max(ans, i);
            }
        }
    }

    cout << ans << endl;
}
     
int32_t main() {
    cin.tie(NULL)->sync_with_stdio(false);
    cout.precision(10);

    preprocess(); 

    int T = 1;
    cin >> T;

    for (int i = 1; i <= T; i++) {
        solve(i);
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1146 Yet Another Battle Between Roy and Hridoy!
Contest
LU Divisonal Contest Problem Testing Round
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-05 09:05:03
Judged At
2024-12-08 18:06:45
Judged By
Score
95
Total Time
1384ms
Peak Memory
25.445 MiB