답안 #270526

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
270526 2020-08-17T17:34:57 Z Haunted_Cpp Discharging (NOI20_discharging) C++17
0 / 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 - 1, 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 - 1, 0) * (n - j));
    }
    //~ cout << best_way.second << '\n';
  }
  cout << dp[n] << '\n';
  return 0;
}
 
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 31616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 169 ms 31648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 169 ms 31648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 47352 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 31616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 31616 KB Output isn't correct
2 Halted 0 ms 0 KB -