/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 520.0 KiB
#3 Accepted 35ms 532.0 KiB
#4 Wrong Answer 1355ms 800.0 KiB
#5 Time Exceeded ≥2000ms ≥1000.0 KiB
#6 Time Exceeded ≥2100ms ≥4.68 MiB
#7 Time Exceeded ≥2101ms ≥17.789 MiB
#8 Time Exceeded ≥2001ms ≥7.129 MiB
#9 Time Exceeded ≥2099ms ≥10.117 MiB
#10 Time Exceeded ≥2100ms ≥2.887 MiB
#11 Time Exceeded ≥2100ms ≥2.867 MiB
#12 Time Exceeded ≥2101ms ≥17.793 MiB
#13 Time Exceeded ≥2102ms ≥20.039 MiB
#14 Time Exceeded ≥2102ms ≥39.648 MiB
#15 Time Exceeded ≥2098ms ≥4.672 MiB
#16 Accepted 18ms 804.0 KiB
#17 Accepted 19ms 836.0 KiB
#18 Time Exceeded ≥2099ms ≥4.633 MiB
#19 Time Exceeded ≥2001ms ≥3.703 MiB
#20 Time Exceeded ≥2099ms ≥3.684 MiB

Code

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
using ll = long long;
using P = pair<int,int>;

int main() {
  FAST;
  
  int tc = 1, ti;
  cin >> tc;

  for (ti = 1; ti <= tc; ++ti) {
    int n, k, i, j, d, dd, g;
    cin >> n >> k;

    vector<int> a(n);
    for (i = 0; i < n; ++i) cin >> a[i];

    map<int,vector<int>> mp;
    for (i = 0; i < n; ++i) mp[a[i]].push_back(i);

    priority_queue<P, vector<P>, greater<P>> pq;
    vector<int> dis(n, INT_MAX);
    pq.emplace(0, 0);
    
    for (int z : mp[a[0]]) dis[z] = 1;
    dis[0] = 0;

    while (!pq.empty()) {
      tie(d, i) = pq.top(); pq.pop();
      if (dis[i] != d) continue;

      if (i < n-1) {
        dd = d+k;
        j = i+1;
        if (dis[j] > dd) {
          dis[j] = dd;
          pq.emplace(dd, j);
        }
      }

      for (j = i+1; j < n; ++j) {
        if (dis[j] <= d) continue;
        g = gcd(a[i], a[j]);
        dd = d + a[i]/g;
        if (dis[j] > dd) {
          for (int z : mp[a[j]]) {
            if (z <= i) continue;
            if (dis[z] > dd) {
              dis[z] = dd;
              pq.emplace(dd, z);
            }
          }
        }
      }
    }

    cout << dis[n-1] << "\n";
  }

  return 0;
}

Information

Submit By
Type
Submission
Problem
P1099 Which way to go
Contest
Brain Booster #6
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 17:47:34
Judged At
2024-10-03 17:47:34
Judged By
Score
25
Total Time
≥2102ms
Peak Memory
≥39.648 MiB