Submission #708759

# Submission time Handle Problem Language Result Execution time Memory
708759 2023-03-12T09:10:20 Z PixelCat Two Dishes (JOI19_dishes) C++14
10 / 100
54 ms 32076 KB
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;

// const int MAXN = 1000010;
const int MAXN = 2010;

int a1[MAXN];
int s1[MAXN];
int p1[MAXN];
int pr1[MAXN];
int t1[MAXN];

int a2[MAXN];
int s2[MAXN];
int p2[MAXN];
int pr2[MAXN];
int t2[MAXN];

int su[MAXN][MAXN];
int dp[MAXN];
int dp2[MAXN][MAXN];

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // NYA =^-w-^=
    int n, m;
// #define QWQ
#ifndef QWQ
    cin >> n >> m;
    assert(n <= MAXN);
    For(i, 1, n) {
        cin >> a1[i] >> s1[i] >> p1[i];
        pr1[i] = pr1[i - 1] + a1[i];
    }
    For(i, 1, m) {
        cin >> a2[i] >> s2[i] >> p2[i];
        pr2[i] = pr2[i - 1] + a2[i];
    }
#else
    mt19937 rng(48763);
    n = m = 5;
    For(i, 1, n) {
        a1[i] = rng() % 10 + 1;
        s1[i] = rng() % 100 + 1;
        p1[i] = 1;
        pr1[i] = pr1[i - 1] + a1[i];
    }
    For(i, 1, m) {
        a2[i] = rng() % 10 + 1;
        s2[i] = rng() % 100 + 1;
        p2[i] = 1;
        pr2[i] = pr2[i - 1] + a2[i];
    }
#endif

    For(i, 1, n) {
        auto it = upper_bound(pr2, pr2 + m + 1, s1[i] - pr1[i]);
        t1[i] = it - pr2 - 1;
        // cout << i << " " << t1[i] << "\n";
        // dp2[i][0] = dp2[i - 1][0] + (t1[i] >= 0);
    }
    // cout << "\n";
    
    For(i, 1, m) {
        auto it = upper_bound(pr1, pr1 + n + 1, s2[i] - pr2[i]);
        t2[i] = it - pr1 - 1;
        // cout << i << " " << t2[i] << "\n";
        // dp2[0][i] = dp2[0][i - 1] + (t2[i] >= 0);
        For(j, 0, t2[i]) {
            su[j][i]++;
        }
    }
    // cout << "\n";

    // For(i, 1, n) For(j, 1, m) {
    //     dp2[i][j] = max(dp2[i - 1][j] + (j <= t1[i]), dp2[i][j - 1] + (i <= t2[j]));
    // }
    // For(i, 0, n) For(j, 0, m) cout << dp2[i][j] << " \n"[j == m];
    // cout << "\n";
    // cout << dp[n][m] << "\n";

    For(i, 0, n) For(j, 1, m) su[i][j] += su[i][j - 1];
    int ans = su[0][m];
    For(i, 1, n) if(t1[i] >= 0) {
        int add = 0;
        // dp[i] = su[0][t1[i]] + 1;
        dp[i] = 0;
        Forr(i2, i - 1, 1) if(t1[i2] >= 0) {
            if(t1[i2] > t1[i]) add++;
            else {
                dp[i] = max(dp[i], dp[i2] + su[i2][t1[i]] - su[i2][t1[i2]] + add + 1);
            }
        }
        dp[i] = max(dp[i], su[0][t1[i]] + add + 1);
        // cout << i << " " << dp[i] << "\n";
        ans = max(ans, dp[i] + su[i][m] - su[i][t1[i]]);
        // cout << dp[i] << " " << dp2[i][t1[i]] << endl;
        // assert(dp[i] == dp2[i][t1[i]]);
    }
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 50 ms 32020 KB Output is correct
18 Correct 25 ms 31948 KB Output is correct
19 Correct 51 ms 32076 KB Output is correct
20 Correct 33 ms 31972 KB Output is correct
21 Correct 54 ms 30804 KB Output is correct
22 Correct 49 ms 31996 KB Output is correct
23 Correct 51 ms 32000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 50 ms 32020 KB Output is correct
18 Correct 25 ms 31948 KB Output is correct
19 Correct 51 ms 32076 KB Output is correct
20 Correct 33 ms 31972 KB Output is correct
21 Correct 54 ms 30804 KB Output is correct
22 Correct 49 ms 31996 KB Output is correct
23 Correct 51 ms 32000 KB Output is correct
24 Runtime error 2 ms 468 KB Execution killed with signal 6
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 50 ms 32020 KB Output is correct
18 Correct 25 ms 31948 KB Output is correct
19 Correct 51 ms 32076 KB Output is correct
20 Correct 33 ms 31972 KB Output is correct
21 Correct 54 ms 30804 KB Output is correct
22 Correct 49 ms 31996 KB Output is correct
23 Correct 51 ms 32000 KB Output is correct
24 Runtime error 2 ms 468 KB Execution killed with signal 6
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 328 KB Output is correct
17 Correct 50 ms 32020 KB Output is correct
18 Correct 25 ms 31948 KB Output is correct
19 Correct 51 ms 32076 KB Output is correct
20 Correct 33 ms 31972 KB Output is correct
21 Correct 54 ms 30804 KB Output is correct
22 Correct 49 ms 31996 KB Output is correct
23 Correct 51 ms 32000 KB Output is correct
24 Runtime error 2 ms 468 KB Execution killed with signal 6
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -