답안 #931172

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931172 2024-02-21T10:35:12 Z VMaksimoski008 메기 농장 (IOI22_fish) C++17
18 / 100
63 ms 7272 KB
#include <bits/stdc++.h>

#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;
using ll = long long;

int64_t max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
    bool even = true, sub2 = true, sub3 = true;

    for(int i=0; i<m; i++) {
        if(x[i] % 2 == 1) even = false;
        if(x[i] > 1) sub2 = false;
        if(y[i] > 0) sub3 = false;
    }

    if(even) {
        ll ans = 0;
        for(int &x : w) ans += x;
        return ans;
    }

    if(sub2) {
        ll ans = 0, pref[n][2];

        memset(pref, 0, sizeof(pref));
        for(int i=0; i<m; i++)
            pref[y[i]][x[i]] += w[i];

        for(int i=1; i<n; i++) {
            pref[i][0] += pref[i-1][0];
            pref[i][1] += pref[i-1][1];
        }

        if(n == 2) return max(pref[n-1][0], pref[n-1][1]);

        for(int i=0; i<n; i++)
            ans = max(ans, pref[i][0] + pref[n-1][1] - pref[i][1]);
        return max({ ans, pref[n-1][0], pref[n-1][1] });
    }

    if(sub3) {
        vector<int> v(n, 0);
        vector<ll> dp(n, 0);
        vector<ll> mx(n, 0);

        for(int i=0; i<m; i++)
            v[x[i]] = w[i];

        dp[0] = (n > 1 ? v[1] : 0);
        mx[0] = dp[0];
        for(int i=1; i<n; i++) {
            ll res1 = dp[i-1] - v[i];
            if(i < n-1) res1 += v[i+1];

            ll res2 = (i > 1 ? dp[i-2] : 0);
            if(i < n-1) res2 += v[i+1];

            ll res3 = (i > 2 ? mx[i-3] : 0);
            res3 += v[i-1];
            if(i < n-1) res3 += v[i+1];

            dp[i] = max({ dp[i], res1, res2, res3 });
            mx[i] = max(mx[i-1], dp[i]);
        }

        return *max_element(all(mx));
    }

    return 0;
}

// int32_t main() {
//     setIO();

//     int n, m;
//     cin >> n >> m;

//     vector<int> x(m), y(m), w(m);
//     for(int i=0; i<m; i++)
//         cin >> x[i] >> y[i] >> w[i];
    
//     cout << max_weights(n, m, x, y, w) << '\n';
//     return 0;
// }
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 2388 KB Output is correct
2 Correct 21 ms 2648 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 61 ms 7256 KB Output is correct
6 Correct 63 ms 7272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 48 ms 5420 KB Output is correct
3 Correct 43 ms 6628 KB Output is correct
4 Correct 21 ms 2136 KB Output is correct
5 Correct 21 ms 2644 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 17 ms 3676 KB Output is correct
13 Correct 22 ms 4188 KB Output is correct
14 Correct 18 ms 3672 KB Output is correct
15 Correct 20 ms 3932 KB Output is correct
16 Correct 18 ms 3676 KB Output is correct
17 Correct 20 ms 3924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 2200 KB Output is correct
3 Correct 13 ms 3420 KB Output is correct
4 Correct 9 ms 3160 KB Output is correct
5 Correct 23 ms 4700 KB Output is correct
6 Correct 19 ms 4696 KB Output is correct
7 Correct 22 ms 4956 KB Output is correct
8 Correct 23 ms 4572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 2200 KB Output is correct
3 Correct 13 ms 3420 KB Output is correct
4 Correct 9 ms 3160 KB Output is correct
5 Correct 23 ms 4700 KB Output is correct
6 Correct 19 ms 4696 KB Output is correct
7 Correct 22 ms 4956 KB Output is correct
8 Correct 23 ms 4572 KB Output is correct
9 Incorrect 18 ms 2652 KB 1st lines differ - on the 1st token, expected: '99999', found: '0'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 2388 KB Output is correct
2 Correct 21 ms 2648 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 61 ms 7256 KB Output is correct
6 Correct 63 ms 7272 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 48 ms 5420 KB Output is correct
9 Correct 43 ms 6628 KB Output is correct
10 Correct 21 ms 2136 KB Output is correct
11 Correct 21 ms 2644 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 17 ms 3676 KB Output is correct
19 Correct 22 ms 4188 KB Output is correct
20 Correct 18 ms 3672 KB Output is correct
21 Correct 20 ms 3932 KB Output is correct
22 Correct 18 ms 3676 KB Output is correct
23 Correct 20 ms 3924 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 2200 KB Output is correct
26 Correct 13 ms 3420 KB Output is correct
27 Correct 9 ms 3160 KB Output is correct
28 Correct 23 ms 4700 KB Output is correct
29 Correct 19 ms 4696 KB Output is correct
30 Correct 22 ms 4956 KB Output is correct
31 Correct 23 ms 4572 KB Output is correct
32 Incorrect 0 ms 348 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
33 Halted 0 ms 0 KB -