Submission #973677

# Submission time Handle Problem Language Result Execution time Memory
973677 2024-05-02T09:30:35 Z Ooops_sorry Constellation 3 (JOI20_constellation3) C++14
35 / 100
1500 ms 29992 KB
#include<iostream>
#include<deque>
#include<algorithm>
#include<vector>
#include<map>
#include<random>
#include<time.h>
#include<cassert>
#include<chrono>
#include<set>
#include<unordered_set>
#include<array>
 
using namespace std;
 
#define ull unsigned long long
#define pb push_back
#define ll long long
#define all(a) a.begin(), a.end()
#define ld long double 
#define int long long 

mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

const int N = 2e5 + 10;
vector<pair<int, ll>> mas[N];
int a[N];

vector<pair<int, ll>> solve(int l, int r) {
  if (l == r) {
    sort(all(mas[l]));
    return mas[l];
  }
  int total = 0;
  for (int i = l; i <= r; i++) {
    total += mas[i].size();
  }
  if (total == 0) {
    return vector<pair<int, ll>>{};
  }
  int m = l;
  for (int i = l + 1; i <= r; i++) {
    if (a[i] > a[m]) {
      m = i;
    }
  }
  auto arr1 = solve(l, m - 1), arr2 = solve(m + 1, r);
  ll best1 = 0, best2 = 0;
  for (auto p : arr1) {
    if (p.first <= a[m]) {
      best1 = max(best1, p.second);
    }
  }
  for (auto p : arr2) {
    if (p.first <= a[m]) {
      best2 = max(best2, p.second);
    }
  }
  vector<pair<int, ll>> res;
  {
    int j = -1;
    ll best = 0;
    for (auto p : arr1) {
      while (j + 1 < arr2.size() && arr2[j + 1].first <= p.first) {
        j++;
        best = max(best, arr2[j].second);
      }
      if (p.first <= a[m]) {
        res.pb({p.first, p.second + best});
      } else {
        res.pb({p.first, p.second + best2});
      }
    }
  }
  {
    int j = -1;
    ll best = 0;
    for (auto p : arr2) {
      while (j + 1 < arr1.size() && arr1[j + 1].first <= p.first) {
        j++;
        best = max(best, arr1[j].second);
      }
      if (p.first <= a[m]) {
        res.pb({p.first, p.second + best});
      } else {
        res.pb({p.first, p.second + best1});
      }
    }
  }
  for (auto p : mas[m]) {
    res.pb({p.first, p.second + best1 + best2});
  }
  sort(all(res));
  return res;
}

signed main() {
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif // LOCAL
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int m;
  cin >> m;
  ll sum = 0;
  for (int i = 0; i < m; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    if (y <= a[x]) continue;
    sum += c;
    mas[x].pb({y, c});
  }
  auto res = solve(0, n - 1);
  ll mx = 0;
  for (auto p : res) {
    mx = max(mx, p.second);
  }
  cout << sum - mx << endl;
  return 0; 
}

Compilation message

constellation3.cpp: In function 'std::vector<std::pair<long long int, long long int> > solve(long long int, long long int)':
constellation3.cpp:64:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |       while (j + 1 < arr2.size() && arr2[j + 1].first <= p.first) {
      |              ~~~~~~^~~~~~~~~~~~~
constellation3.cpp:79:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |       while (j + 1 < arr1.size() && arr1[j + 1].first <= p.first) {
      |              ~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 3 ms 6552 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 3 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 3 ms 6492 KB Output is correct
11 Correct 2 ms 6548 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 3 ms 6492 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 3 ms 6744 KB Output is correct
16 Correct 3 ms 6492 KB Output is correct
17 Correct 2 ms 6588 KB Output is correct
18 Correct 3 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 4 ms 6492 KB Output is correct
22 Correct 2 ms 6732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 3 ms 6552 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 3 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 3 ms 6492 KB Output is correct
11 Correct 2 ms 6548 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 3 ms 6492 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 3 ms 6744 KB Output is correct
16 Correct 3 ms 6492 KB Output is correct
17 Correct 2 ms 6588 KB Output is correct
18 Correct 3 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 4 ms 6492 KB Output is correct
22 Correct 2 ms 6732 KB Output is correct
23 Correct 5 ms 6556 KB Output is correct
24 Correct 4 ms 7000 KB Output is correct
25 Correct 5 ms 6744 KB Output is correct
26 Correct 4 ms 6748 KB Output is correct
27 Correct 4 ms 6748 KB Output is correct
28 Correct 4 ms 6716 KB Output is correct
29 Correct 4 ms 6744 KB Output is correct
30 Correct 4 ms 6748 KB Output is correct
31 Correct 3 ms 6656 KB Output is correct
32 Correct 53 ms 6860 KB Output is correct
33 Correct 39 ms 6948 KB Output is correct
34 Correct 33 ms 6748 KB Output is correct
35 Correct 34 ms 6748 KB Output is correct
36 Correct 36 ms 7028 KB Output is correct
37 Correct 49 ms 7032 KB Output is correct
38 Correct 70 ms 7004 KB Output is correct
39 Correct 4 ms 6744 KB Output is correct
40 Correct 54 ms 7120 KB Output is correct
41 Correct 6 ms 6560 KB Output is correct
42 Correct 4 ms 6620 KB Output is correct
43 Correct 57 ms 7132 KB Output is correct
44 Correct 4 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 2 ms 6492 KB Output is correct
3 Correct 2 ms 6492 KB Output is correct
4 Correct 3 ms 6552 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 3 ms 6492 KB Output is correct
7 Correct 2 ms 6492 KB Output is correct
8 Correct 2 ms 6492 KB Output is correct
9 Correct 2 ms 6492 KB Output is correct
10 Correct 3 ms 6492 KB Output is correct
11 Correct 2 ms 6548 KB Output is correct
12 Correct 2 ms 6492 KB Output is correct
13 Correct 3 ms 6492 KB Output is correct
14 Correct 2 ms 6492 KB Output is correct
15 Correct 3 ms 6744 KB Output is correct
16 Correct 3 ms 6492 KB Output is correct
17 Correct 2 ms 6588 KB Output is correct
18 Correct 3 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 4 ms 6492 KB Output is correct
22 Correct 2 ms 6732 KB Output is correct
23 Correct 5 ms 6556 KB Output is correct
24 Correct 4 ms 7000 KB Output is correct
25 Correct 5 ms 6744 KB Output is correct
26 Correct 4 ms 6748 KB Output is correct
27 Correct 4 ms 6748 KB Output is correct
28 Correct 4 ms 6716 KB Output is correct
29 Correct 4 ms 6744 KB Output is correct
30 Correct 4 ms 6748 KB Output is correct
31 Correct 3 ms 6656 KB Output is correct
32 Correct 53 ms 6860 KB Output is correct
33 Correct 39 ms 6948 KB Output is correct
34 Correct 33 ms 6748 KB Output is correct
35 Correct 34 ms 6748 KB Output is correct
36 Correct 36 ms 7028 KB Output is correct
37 Correct 49 ms 7032 KB Output is correct
38 Correct 70 ms 7004 KB Output is correct
39 Correct 4 ms 6744 KB Output is correct
40 Correct 54 ms 7120 KB Output is correct
41 Correct 6 ms 6560 KB Output is correct
42 Correct 4 ms 6620 KB Output is correct
43 Correct 57 ms 7132 KB Output is correct
44 Correct 4 ms 6748 KB Output is correct
45 Correct 341 ms 27740 KB Output is correct
46 Correct 288 ms 29624 KB Output is correct
47 Correct 333 ms 29636 KB Output is correct
48 Correct 267 ms 28600 KB Output is correct
49 Correct 324 ms 28788 KB Output is correct
50 Correct 294 ms 28308 KB Output is correct
51 Correct 299 ms 28976 KB Output is correct
52 Correct 292 ms 28904 KB Output is correct
53 Correct 302 ms 29992 KB Output is correct
54 Execution timed out 1529 ms 18088 KB Time limit exceeded
55 Halted 0 ms 0 KB -