답안 #591257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
591257 2022-07-07T07:01:47 Z 이동현(#8420) Two Dishes (JOI19_dishes) C++17
10 / 100
725 ms 1048576 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

struct mxSeg{
    int n;
    vector<int> tr;
    mxSeg(){}
    mxSeg(int n):n(n + 4){
        tr.resize(n * 4);
    }
    void push(int x, int s, int e, int pos, int val){
        if(pos < s || pos > e) return;
        if(s == e){
            tr[x] = max(tr[x], val);
            return;
        }
        int m = s + e >> 1;
        push(x * 2, s, m, pos, val), push(x * 2 + 1, m + 1, e, pos, val);
        tr[x] = max(tr[x * 2], tr[x * 2 + 1]);
    }
    int get(int x, int s, int e, int fs, int fe, int val){
        if(fe < s || fs > e || tr[x] < val) return (int)1e18;
        if(s == e) return s;
        int m = s + e >> 1;
        int p1 = get(x * 2, s, m, fs, fe, val);
        if(p1 < (int)1e18) return p1;
        return get(x * 2 + 1, m + 1, e, fs, fe, val);
    }
};

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m; cin >> n >> m;
    vector<vector<int>> a(n, vector<int>(3)), b(m, vector<int>(3));
    mxSeg aseg(n), bseg(m);
    for(int i = 0; i < n; ++i){
        cin >> a[i][0] >> a[i][1] >> a[i][2];
        if(i) a[i][0] += a[i - 1][0];
        //aseg.push(1, 0, n - 1, i, a[i][1] - a[i][0]);
    }
    for(int i = 0; i < m; ++i){
        cin >> b[i][0] >> b[i][1] >> b[i][2];
        if(i) b[i][0] += b[i - 1][0];
        //bseg.push(1, 0, m - 1, i, b[i][1] - b[i][0]);
    }
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, -(int)1e18));
    dp[0][0] = 0;
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= m; ++j){
            int t = 0;
            if(i) t += a[i - 1][0];
            if(j) t += b[j - 1][0];
            if(i < n) dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + (t + a[i][0] - (i ? a[i - 1][0] : 0) <= a[i][1]) * a[i][2]);
            if(j < m) dp[i][j + 1] = max(dp[i][j + 1], dp[i][j] + (t + b[j][0] - (j ? b[j - 1][0] : 0) <= b[j][1]) * b[j][2]);
        }
    }
    cout << dp[n][m] << '\n';
    return 0;
}

Compilation message

dishes.cpp: In member function 'void mxSeg::push(long long int, long long int, long long int, long long int, long long int)':
dishes.cpp:18:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   18 |         int m = s + e >> 1;
      |                 ~~^~~
dishes.cpp: In member function 'long long int mxSeg::get(long long int, long long int, long long int, long long int, long long int, long long int)':
dishes.cpp:25:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |         int m = s + e >> 1;
      |                 ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 725 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 46 ms 32148 KB Output is correct
18 Correct 46 ms 32144 KB Output is correct
19 Correct 44 ms 32124 KB Output is correct
20 Correct 40 ms 29776 KB Output is correct
21 Correct 43 ms 30908 KB Output is correct
22 Correct 43 ms 32084 KB Output is correct
23 Correct 46 ms 32108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 46 ms 32148 KB Output is correct
18 Correct 46 ms 32144 KB Output is correct
19 Correct 44 ms 32124 KB Output is correct
20 Correct 40 ms 29776 KB Output is correct
21 Correct 43 ms 30908 KB Output is correct
22 Correct 43 ms 32084 KB Output is correct
23 Correct 46 ms 32108 KB Output is correct
24 Runtime error 525 ms 1048576 KB Execution killed with signal 9
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 46 ms 32148 KB Output is correct
18 Correct 46 ms 32144 KB Output is correct
19 Correct 44 ms 32124 KB Output is correct
20 Correct 40 ms 29776 KB Output is correct
21 Correct 43 ms 30908 KB Output is correct
22 Correct 43 ms 32084 KB Output is correct
23 Correct 46 ms 32108 KB Output is correct
24 Runtime error 525 ms 1048576 KB Execution killed with signal 9
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 316 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 46 ms 32148 KB Output is correct
18 Correct 46 ms 32144 KB Output is correct
19 Correct 44 ms 32124 KB Output is correct
20 Correct 40 ms 29776 KB Output is correct
21 Correct 43 ms 30908 KB Output is correct
22 Correct 43 ms 32084 KB Output is correct
23 Correct 46 ms 32108 KB Output is correct
24 Runtime error 525 ms 1048576 KB Execution killed with signal 9
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 725 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 725 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -