답안 #946882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946882 2024-03-15T07:11:37 Z vjudge1 별자리 3 (JOI20_constellation3) C++17
14 / 100
1500 ms 29276 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

struct Sp{
    vector <vector<int>> T;
    int _s;
    Sp(auto &a, int s){
        _s = s;
        T.resize(20);
        int n = a.size();
        for ( auto &x: T ){
            x.resize(n);
        }
        T[0] = a;
        for ( auto &u: T[0] ) u *= _s;
        for ( int i = 1; i < 20; i++ ){
            int k = 1 << i - 1;
            for ( int j = 0; j < n; j++ ){
                T[i][j] = min(T[i - 1][j], T[i - 1][min(n - 1, j + k)]);
            }
        }
    }
    int get(int l, int r){
        int lg = __lg(r - l + 1), k = 1 << lg;
        return min(T[lg][l], T[lg][r - k + 1]) * _s;
    }
};

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    vector <int> a(n);
    for ( auto &u: a ) cin >> u;
    int m; cin >> m;
    vector <int> X(m), Y(m), C(m);
    vector <vector<int>> G(n);
    for ( int i = 0; i < m; i++ ){
        cin >> X[i] >> Y[i] >> C[i];
        --X[i];
        G[X[i]].pb(i);
    }
    vector <int> L(m), R(m);
    Sp sp(a, -1);
    for ( int i = 0; i < n; i++ ){
        for ( auto &j: G[i] ){
            int l = 0, r = n;
            L[j] = R[j] = i;
            while ( l < L[j] ){
                int md = (l + L[j]) / 2;
                if ( sp.get(md, L[j]) >= Y[j] ){
                    l = md + 1;
                } else L[j] = md;
            }
            while ( R[j] + 1 < r ){
                int md = (R[j] + r) / 2;
                if ( sp.get(R[j], md) >= Y[j] ){
                    r = md;
                } else R[j] = md;
            }
            R[j]++, L[j]++, X[j]++;
        }
    }
    vector <int> pos(m);
    iota(all(pos), 0);
    sort(all(pos), [&](int &u, int &v){
         return Y[u] < Y[v];
    });
    vector <vector<int>> dp(n + 2, vector <int> (n + 1));
    for ( auto &i: pos ){
        for ( int l = n; l > 0; l-- ){
            for ( int r = l; r <= n; r++ ){
                int p = min(L[i], l), q = max(r, R[i]);
                chmax(dp[l][r], max(dp[l + 1][r], dp[l][r - 1]));
                chmax(dp[p][q], dp[p][X[i] - 1] + dp[X[i] + 1][q] + C[i]);
            }
        }
    }
    cout << accumulate(all(C), 0LL) - dp[1][n];

    cout << '\n';
}

Compilation message

constellation3.cpp:34:8: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   34 |     Sp(auto &a, int s){
      |        ^~~~
constellation3.cpp: In instantiation of 'Sp::Sp(auto:23&, long long int) [with auto:23 = std::vector<long long int>]':
constellation3.cpp:72:16:   required from here
constellation3.cpp:44:28: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   44 |             int k = 1 << i - 1;
      |                          ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 1120 KB Output is correct
2 Correct 48 ms 1116 KB Output is correct
3 Correct 51 ms 1116 KB Output is correct
4 Correct 43 ms 1160 KB Output is correct
5 Correct 44 ms 1116 KB Output is correct
6 Correct 46 ms 1116 KB Output is correct
7 Correct 41 ms 1112 KB Output is correct
8 Correct 49 ms 1200 KB Output is correct
9 Correct 48 ms 1196 KB Output is correct
10 Correct 51 ms 1244 KB Output is correct
11 Correct 45 ms 1232 KB Output is correct
12 Correct 50 ms 1368 KB Output is correct
13 Correct 44 ms 1268 KB Output is correct
14 Correct 42 ms 1116 KB Output is correct
15 Correct 46 ms 1192 KB Output is correct
16 Correct 50 ms 1112 KB Output is correct
17 Correct 53 ms 1116 KB Output is correct
18 Correct 41 ms 1112 KB Output is correct
19 Correct 46 ms 1116 KB Output is correct
20 Correct 38 ms 1128 KB Output is correct
21 Correct 43 ms 1116 KB Output is correct
22 Correct 45 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 1120 KB Output is correct
2 Correct 48 ms 1116 KB Output is correct
3 Correct 51 ms 1116 KB Output is correct
4 Correct 43 ms 1160 KB Output is correct
5 Correct 44 ms 1116 KB Output is correct
6 Correct 46 ms 1116 KB Output is correct
7 Correct 41 ms 1112 KB Output is correct
8 Correct 49 ms 1200 KB Output is correct
9 Correct 48 ms 1196 KB Output is correct
10 Correct 51 ms 1244 KB Output is correct
11 Correct 45 ms 1232 KB Output is correct
12 Correct 50 ms 1368 KB Output is correct
13 Correct 44 ms 1268 KB Output is correct
14 Correct 42 ms 1116 KB Output is correct
15 Correct 46 ms 1192 KB Output is correct
16 Correct 50 ms 1112 KB Output is correct
17 Correct 53 ms 1116 KB Output is correct
18 Correct 41 ms 1112 KB Output is correct
19 Correct 46 ms 1116 KB Output is correct
20 Correct 38 ms 1128 KB Output is correct
21 Correct 43 ms 1116 KB Output is correct
22 Correct 45 ms 1116 KB Output is correct
23 Execution timed out 1560 ms 29276 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 1120 KB Output is correct
2 Correct 48 ms 1116 KB Output is correct
3 Correct 51 ms 1116 KB Output is correct
4 Correct 43 ms 1160 KB Output is correct
5 Correct 44 ms 1116 KB Output is correct
6 Correct 46 ms 1116 KB Output is correct
7 Correct 41 ms 1112 KB Output is correct
8 Correct 49 ms 1200 KB Output is correct
9 Correct 48 ms 1196 KB Output is correct
10 Correct 51 ms 1244 KB Output is correct
11 Correct 45 ms 1232 KB Output is correct
12 Correct 50 ms 1368 KB Output is correct
13 Correct 44 ms 1268 KB Output is correct
14 Correct 42 ms 1116 KB Output is correct
15 Correct 46 ms 1192 KB Output is correct
16 Correct 50 ms 1112 KB Output is correct
17 Correct 53 ms 1116 KB Output is correct
18 Correct 41 ms 1112 KB Output is correct
19 Correct 46 ms 1116 KB Output is correct
20 Correct 38 ms 1128 KB Output is correct
21 Correct 43 ms 1116 KB Output is correct
22 Correct 45 ms 1116 KB Output is correct
23 Execution timed out 1560 ms 29276 KB Time limit exceeded
24 Halted 0 ms 0 KB -