답안 #624377

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
624377 2022-08-08T05:29:23 Z brucecccccc Shortcut (IOI16_shortcut) C++14
0 / 100
1 ms 340 KB
#include "shortcut.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll find_shortcut(int n, vector<int> l, vector<int> d, int c) {
  vector<ll> prefix(n);
  for (int i = 1; i < n; i++) {
    prefix[i] = prefix[i-1] + l[i-1];
  }

  vector<vector<ll>> maxFrom(n, vector<ll>(n));
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    auto& m = maxFrom[i];
    for (int j = i+1; j < n; j++) {
      ll x = prefix[j] - prefix[i] + d[j];
      ans = max(ans, x + d[i]);
      m[j] = max(m[j-1], x);
    }
    for (int j = i-1; j >= 0; j--) {
      ll x = prefix[i] - prefix[j] + d[j];
      ans = max(ans, x + d[i]);
      m[j] = max(m[j+1], x);
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (prefix[j] - prefix[i] <= c) continue;
      ll a = 0;
      int s = i;
      while (s + 1 <= j && prefix[s + 1] - prefix[i] < c + prefix[j] - prefix[s + 1]) {
        s++;
      }
      for (int b = 0; b <= i; b++) {
        a = max(a, d[b] + maxFrom[b][i]);
        a = max(a, d[b] + prefix[i] - prefix[b] + c + max((ll) d[j], maxFrom[j][n-1]));
      }
      for (int b = j; b < n; b++) {
        a = max(a, d[b] + maxFrom[b][n-1]);
        a = max(a, d[b] + prefix[j] - prefix[b] + c + max((ll) d[i], maxFrom[i][0]));
      }

      // if (i == 1 && j == 3) {
      //   cout << a << endl;
      // }
      
      for (int b = i+1; b < j; b++) {
        s = max(s, b);

        while (s >= b && s+1 <= j && prefix[s+1] - prefix[b] < c + prefix[j] - prefix[s+1] + prefix[b] - prefix[i]) {
          s++;
          if (s == j) s = i;
        }
        while (s < b && c + prefix[j] - prefix[b] + prefix[s] - prefix[i] < prefix[b] - prefix[s]) {
          s++;
        }

        if (s > b) {
          // a = max(a, maxFrom[b][i]);
          a = max(a, d[b] + prefix[b] - prefix[i] + max((ll) d[i], maxFrom[i][0]));
          a = max(a, d[b] + prefix[b] - prefix[i] + c + max((ll) d[j], max(maxFrom[j][s+1], maxFrom[j][n-1])));
          a = max(a, d[b] + maxFrom[b][s]);
        } else if (s == i) {
          a = max(a, d[b] + maxFrom[b][n-1]);
          a = max(a, d[b] + maxFrom[b][0]);
        } else {
          a = max(a, d[b] + prefix[j] - prefix[b] + max((ll) d[j], maxFrom[j][n-1]));
          a = max(a, d[b] + prefix[j] - prefix[b] + c + max((ll) d[i], max(maxFrom[i][s], maxFrom[i][0])));
        }

        
      }
      
      
      // cout << i << ' ' << j << endl;
      
      // cout << a << endl;
      ans = min(ans, a);
    }
  }

  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 0 ms 212 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 308 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 308 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Incorrect 1 ms 340 KB n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 0 ms 212 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 308 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 308 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Incorrect 1 ms 340 KB n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 0 ms 212 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 308 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 308 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Incorrect 1 ms 340 KB n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 0 ms 212 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 308 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 308 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Incorrect 1 ms 340 KB n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 0 ms 212 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 308 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 308 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Incorrect 1 ms 340 KB n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 0 ms 212 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 308 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 308 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Incorrect 1 ms 340 KB n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 0 ms 212 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 308 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 308 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Incorrect 1 ms 340 KB n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB n = 4, 80 is a correct answer
2 Correct 0 ms 212 KB n = 9, 110 is a correct answer
3 Correct 0 ms 212 KB n = 4, 21 is a correct answer
4 Correct 0 ms 212 KB n = 3, 4 is a correct answer
5 Correct 0 ms 212 KB n = 2, 62 is a correct answer
6 Correct 1 ms 212 KB n = 2, 3 is a correct answer
7 Correct 0 ms 308 KB n = 3, 29 is a correct answer
8 Correct 1 ms 212 KB n = 2, 3 is a correct answer
9 Correct 1 ms 212 KB n = 2, 3 is a correct answer
10 Correct 1 ms 212 KB n = 2, 2000000001 is a correct answer
11 Correct 1 ms 308 KB n = 2, 3000000000 is a correct answer
12 Correct 0 ms 212 KB n = 3, 3000000000 is a correct answer
13 Correct 1 ms 212 KB n = 3, 3000000000 is a correct answer
14 Incorrect 1 ms 340 KB n = 4, incorrect answer: jury 3000000001 vs contestant 4000000000
15 Halted 0 ms 0 KB -