Submission #962828

#TimeUsernameProblemLanguageResultExecution timeMemory
962828nguyentunglamShortcut (IOI16_shortcut)C++17
0 / 100
2 ms2396 KiB
#include<bits/stdc++.h>
using namespace std;
#include "shortcut.h"

const int N = 3e3 + 10;

long long f[N][N];

long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c)
{
  assert(n <= 10);
  assert(f[0][1] == 0);
  long long ans = 1e18;
    for(int x = 0; x < n; x++) for(int y = x + 1; y < n; y++) {
      for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) f[i][j] = (i == j ? 0 : 1e16);
      for(int i = 0; i + 1 < n; i++) f[i][i + 1] = f[i + 1][i] = l[i];
      f[x][y] = min(f[x][y], (long long) c);
      f[y][x] = min(f[y][x], (long long) c);
      for(int k = 0; k < n; k++) for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) {
        f[i][j] = min(f[i][j], f[i][k] + f[k][j]);
      }
      long long cost = 0;
      for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) if (i != j) {
        cost = max(cost, f[i][j] + d[i] + d[j]);
      }
      ans = min(ans, cost);
    }
    return ans;
}

#ifdef ngu
int main()
{
  freopen ("task.inp", "r", stdin);
  freopen ("task.out", "w", stdout);
    int n, c;
    assert(2 == scanf("%d%d", &n, &c));

    std::vector<int> l(n - 1);
    std::vector<int> d(n);
    for (int i = 0; i < n - 1; i++)
        assert(1 == scanf("%d", &l[i]));
    for (int i = 0; i < n; i++)
        assert(1 == scanf("%d", &d[i]));

    long long t = find_shortcut(n, l, d, c);


    printf("%lld\n", t);

    return 0;
}
#endif // ngu
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...