답안 #270532

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
270532 2020-08-17T17:40:07 Z Haunted_Cpp Discharging (NOI20_discharging) C++17
36 / 100
1000 ms 47352 KB
/**
 *  author: Haunted_Cpp
**/
 
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
 
template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
 
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
 
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

const int MAX_N = 1e6 + 5;

vector<long long> seg(4 * MAX_N);

void build(int l, int r, int node, const vector<long long> &arr) {
  if (l == r) {
    seg[node] = arr[l];
    return;
  }
  const int mid = l + (r - l) / 2;
  build(l, mid, 2 * node + 1, arr);
  build(mid + 1, r, 2 * node + 2, arr);
  seg[node] = max(seg[2 * node + 1], seg[2 * node + 2]);
}

int rmq(int ql, int qr, int l, int r, int node) {
  if (l > qr || r < ql) return 0;
  if (l >= ql && r <= qr) return seg[node];
  const int mid = l + (r - l) / 2;
  return max(rmq(ql, qr, l, mid, 2 * node + 1), rmq(ql, qr, mid + 1, r, 2 * node + 2));
}


int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); 
  int n;
  cin >> n;
  vector<long long> arr(n + 1);
  for (int i = 1; i <= n; i++) cin >> arr[i];
  vector<long long> dp(n + 1, 1e18);
  build(0, n, 0, arr);
  dp[0] = 0;
  for (int i = 1; i <= n; i++) {
    long long mx = 0;
    //~ pair<long long, int> best_way = {1e18, 1e9};
    for (int j = min(2000, i - 1); j >= 0; j--) {
      mx = max(mx, arr[j + 1]);
      //~ pair<long long, int> cur = {dp[j] + 1LL * mx * (n - j), j};
      //~ best_way = min(best_way, cur);
      dp[i] = min(dp[i], dp[j] + 1LL * rmq(j + 1, i, 0, n, 0) * (n - j));
    }
    //~ cout << best_way.second << '\n';
  }
  cout << dp[n] << '\n';
  return 0;
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 31616 KB Output is correct
2 Correct 18 ms 31616 KB Output is correct
3 Correct 18 ms 31744 KB Output is correct
4 Correct 18 ms 31616 KB Output is correct
5 Correct 17 ms 31616 KB Output is correct
6 Correct 18 ms 31616 KB Output is correct
7 Correct 18 ms 31616 KB Output is correct
8 Correct 18 ms 31616 KB Output is correct
9 Correct 19 ms 31616 KB Output is correct
10 Correct 18 ms 31616 KB Output is correct
11 Correct 18 ms 31616 KB Output is correct
12 Correct 18 ms 31616 KB Output is correct
13 Correct 18 ms 31616 KB Output is correct
14 Correct 18 ms 31616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 31616 KB Output is correct
2 Correct 155 ms 31616 KB Output is correct
3 Correct 160 ms 31616 KB Output is correct
4 Correct 164 ms 31616 KB Output is correct
5 Correct 182 ms 31608 KB Output is correct
6 Correct 162 ms 31636 KB Output is correct
7 Correct 165 ms 31616 KB Output is correct
8 Correct 154 ms 31608 KB Output is correct
9 Correct 171 ms 31608 KB Output is correct
10 Correct 156 ms 31616 KB Output is correct
11 Correct 174 ms 31616 KB Output is correct
12 Correct 158 ms 31616 KB Output is correct
13 Correct 151 ms 31616 KB Output is correct
14 Correct 167 ms 31616 KB Output is correct
15 Correct 158 ms 31744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 168 ms 31616 KB Output is correct
2 Correct 155 ms 31616 KB Output is correct
3 Correct 160 ms 31616 KB Output is correct
4 Correct 164 ms 31616 KB Output is correct
5 Correct 182 ms 31608 KB Output is correct
6 Correct 162 ms 31636 KB Output is correct
7 Correct 165 ms 31616 KB Output is correct
8 Correct 154 ms 31608 KB Output is correct
9 Correct 171 ms 31608 KB Output is correct
10 Correct 156 ms 31616 KB Output is correct
11 Correct 174 ms 31616 KB Output is correct
12 Correct 158 ms 31616 KB Output is correct
13 Correct 151 ms 31616 KB Output is correct
14 Correct 167 ms 31616 KB Output is correct
15 Correct 158 ms 31744 KB Output is correct
16 Execution timed out 1091 ms 47352 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1070 ms 47352 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 31616 KB Output is correct
2 Correct 18 ms 31616 KB Output is correct
3 Correct 18 ms 31744 KB Output is correct
4 Correct 18 ms 31616 KB Output is correct
5 Correct 17 ms 31616 KB Output is correct
6 Correct 18 ms 31616 KB Output is correct
7 Correct 18 ms 31616 KB Output is correct
8 Correct 18 ms 31616 KB Output is correct
9 Correct 19 ms 31616 KB Output is correct
10 Correct 18 ms 31616 KB Output is correct
11 Correct 18 ms 31616 KB Output is correct
12 Correct 18 ms 31616 KB Output is correct
13 Correct 18 ms 31616 KB Output is correct
14 Correct 18 ms 31616 KB Output is correct
15 Correct 168 ms 31616 KB Output is correct
16 Correct 155 ms 31616 KB Output is correct
17 Correct 160 ms 31616 KB Output is correct
18 Correct 164 ms 31616 KB Output is correct
19 Correct 182 ms 31608 KB Output is correct
20 Correct 162 ms 31636 KB Output is correct
21 Correct 165 ms 31616 KB Output is correct
22 Correct 154 ms 31608 KB Output is correct
23 Correct 171 ms 31608 KB Output is correct
24 Correct 156 ms 31616 KB Output is correct
25 Correct 174 ms 31616 KB Output is correct
26 Correct 158 ms 31616 KB Output is correct
27 Correct 151 ms 31616 KB Output is correct
28 Correct 167 ms 31616 KB Output is correct
29 Correct 158 ms 31744 KB Output is correct
30 Correct 155 ms 31648 KB Output is correct
31 Correct 169 ms 31616 KB Output is correct
32 Correct 151 ms 31744 KB Output is correct
33 Correct 159 ms 31744 KB Output is correct
34 Correct 161 ms 31616 KB Output is correct
35 Correct 165 ms 31616 KB Output is correct
36 Correct 163 ms 31616 KB Output is correct
37 Correct 167 ms 31616 KB Output is correct
38 Correct 164 ms 31744 KB Output is correct
39 Correct 166 ms 31616 KB Output is correct
40 Correct 148 ms 31744 KB Output is correct
41 Correct 163 ms 31616 KB Output is correct
42 Correct 167 ms 31616 KB Output is correct
43 Correct 170 ms 31616 KB Output is correct
44 Correct 159 ms 31616 KB Output is correct
45 Correct 155 ms 31744 KB Output is correct
46 Correct 153 ms 31616 KB Output is correct
47 Correct 168 ms 31616 KB Output is correct
48 Correct 156 ms 31616 KB Output is correct
49 Correct 158 ms 31744 KB Output is correct
50 Correct 152 ms 31616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 31616 KB Output is correct
2 Correct 18 ms 31616 KB Output is correct
3 Correct 18 ms 31744 KB Output is correct
4 Correct 18 ms 31616 KB Output is correct
5 Correct 17 ms 31616 KB Output is correct
6 Correct 18 ms 31616 KB Output is correct
7 Correct 18 ms 31616 KB Output is correct
8 Correct 18 ms 31616 KB Output is correct
9 Correct 19 ms 31616 KB Output is correct
10 Correct 18 ms 31616 KB Output is correct
11 Correct 18 ms 31616 KB Output is correct
12 Correct 18 ms 31616 KB Output is correct
13 Correct 18 ms 31616 KB Output is correct
14 Correct 18 ms 31616 KB Output is correct
15 Correct 168 ms 31616 KB Output is correct
16 Correct 155 ms 31616 KB Output is correct
17 Correct 160 ms 31616 KB Output is correct
18 Correct 164 ms 31616 KB Output is correct
19 Correct 182 ms 31608 KB Output is correct
20 Correct 162 ms 31636 KB Output is correct
21 Correct 165 ms 31616 KB Output is correct
22 Correct 154 ms 31608 KB Output is correct
23 Correct 171 ms 31608 KB Output is correct
24 Correct 156 ms 31616 KB Output is correct
25 Correct 174 ms 31616 KB Output is correct
26 Correct 158 ms 31616 KB Output is correct
27 Correct 151 ms 31616 KB Output is correct
28 Correct 167 ms 31616 KB Output is correct
29 Correct 158 ms 31744 KB Output is correct
30 Execution timed out 1091 ms 47352 KB Time limit exceeded
31 Halted 0 ms 0 KB -