Submission #601693

#TimeUsernameProblemLanguageResultExecution timeMemory
601693MazaalaiMeetings (IOI18_meetings)C++17
Compilation error
0 ms0 KiB
#include "meetings.h" #include <bits/stdc++.h> #define sz(x) (int)x.size() #define ALL(x) x.begin(), x.end() #define chmax(a, b) a=max(a,b) #define chmin(a, b) a=min(a,b) #define pb push_back #define ff first #define ss second using namespace std; using ll = long long; using VI = vector <int>; using PII = pair <int, int>; int n, m, q; const int N = 1e5+1; const int M = 3*N const int N1 = 5001; ll dp[N1][N1]; int nums[N]; struct Node { int l, r, mx; } node[M]; Node merge(Node a, Node b) { Node res = {a.l, b.r, max(a.mx, b.mx)}; if (a.l == a.mx && b.l == b.mx) { int x = a.mx + b.mx; res = {x, x, x}; } else if (a.l == a.mx) { res.l = a.mx + b.l; chmax(res.mx, res.l); } else if (b.l == b.mx) { res.r = a.r + b.mx; chmax(res.mx, res.r); } return res; } void build(int l, int r, int head) { if (l == r) { int x = (nums[l] == 1); node[head] = {x, x, x}; return; } int mid = (l+r)>>1; build(l, mid, head*2+1); build(mid+1, r, head*2+2); node[head] = merge(node[head*2+1], node[head*2+2]); } Node zero = {0, 0, 0}; Node query(int l, int r, int L, int R, int head) { if (l > R || L > r) return zero; if (L <= l && r <= R) return node[head]; int mid = (l+r)>>1; return merge( query(l, mid, L, R, head*2+1), query(mid+1, r, L, R, head*2+2) ); } vector<long long> minimum_costs(vector<int> h, vector<int> L, vector<int> R) { n = sz(h); q = sz(L); // cout << n << ' ' << q << '\n'; vector<long long> ans(q, 1e18); if (n < N1) { for (int i = 0; i < n; i++) { for (int j = i, cur = 0; j < n; j++) { cur = max(cur, h[j]); dp[i][j] = cur; if (j > i) dp[i][j] += dp[i][j-1]; } for (int j = i, cur = 0; j >= 0; j--) { cur = max(cur, h[j]); dp[i][j] = cur; if (j < i) dp[i][j] += dp[i][j+1]; } } for (int i = 0; i < q; i++) { int l = L[i], r = R[i]; ll& res = ans[i]; for (int mid = l; mid <= r; mid++) { chmin(res, dp[mid][l]+dp[mid][r]-h[mid]); } } return ans; } else { for (int i = 0; i < n; i++) nums[i] = h[i]; build(0, n-1, 0); for (int i = 0; i < q; i++) { ans[i] = query(0, n-1, L[i], R[i], 0).mx; } } return ans; }

Compilation message (stderr)

meetings.cpp:17:1: error: expected ',' or ';' before 'const'
   17 | const int N1 = 5001;
      | ^~~~~
meetings.cpp:18:7: error: 'N1' was not declared in this scope; did you mean 'N'?
   18 | ll dp[N1][N1];
      |       ^~
      |       N
meetings.cpp:18:11: error: 'N1' was not declared in this scope; did you mean 'N'?
   18 | ll dp[N1][N1];
      |           ^~
      |           N
meetings.cpp: In function 'std::vector<long long int> minimum_costs(std::vector<int>, std::vector<int>, std::vector<int>)':
meetings.cpp:63:13: error: 'N1' was not declared in this scope; did you mean 'N'?
   63 |     if (n < N1) {
      |             ^~
      |             N
meetings.cpp:67:17: error: 'dp' was not declared in this scope
   67 |                 dp[i][j] = cur;
      |                 ^~
meetings.cpp:72:17: error: 'dp' was not declared in this scope
   72 |                 dp[i][j] = cur;
      |                 ^~
meetings.cpp:80:28: error: 'dp' was not declared in this scope
   80 |                 chmin(res, dp[mid][l]+dp[mid][r]-h[mid]);
      |                            ^~
meetings.cpp:6:29: note: in definition of macro 'chmin'
    6 | #define chmin(a, b) a=min(a,b)
      |                             ^