답안 #661002

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
661002 2022-11-23T19:31:37 Z mychecksedad 메기 농장 (IOI22_fish) C++17
9 / 100
201 ms 23780 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
const int S = 1e5 + 100;


ll dp[S][15], a[S][2], s[S], pref[S][15];
long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y, std::vector<int> w){  
    bool case1 = 1, case2 = 1;
    for(int i = 0; i < m; ++i){
        if(x[i] % 2) case1 = 0;
        if(x[i] > 1) case2 = 0;
    }
    if(case1){
        ll ans = 0;
        for(int i = 0; i < m; ++i) ans += w[i];
        return ans;
    }
    if(case2){
        ll ans1 = 0, ans2 = 0;

        for(int i = 0; i < m; ++i){
            if(x[i] == 0) ans1 += w[i];
            else ans2 += w[i];
        }
        if(n == 2)
            return max(ans1, ans2);
        else{
            ll best = 0, sum = 0;
            int p = 0;
            for(int i = 0; i <= n + 1; ++i) a[i][0] = a[i][1] = s[i] = 0;
            for(int i = 0; i < m; i++) if(x[i] == 0) a[y[i]][0] = w[i]; else a[y[i]][1] = w[i];

            for(int i = n; i >= 0; --i) s[i] = s[i + 1] + a[i][1];

            for(int i = 0; i <= n + 1; ++i){
                best = max(best, s[i] + sum);
                sum += a[i][0];
            }

            return best;
        }
    }
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j < 15; ++j) pref[i][j] = dp[i][j] = 0;
    }
    for(int i = 0; i < m; ++i) pref[x[i]][y[i] + 1] = w[i];

    for(int i = 0; i <= n; ++i){
        for(int j = 1; j < 15; ++j) pref[i][j] += pref[i][j - 1];
    }
    for(int i = 1; i <= n; ++i){
        for(int j = 0; j < 10; ++j){
            for(int k = 0; k < 10; ++k){
                ll val;

                if(i == 1){
                    val = (j >= k ? pref[i - 1][j] - pref[i - 1][k] : pref[i][k] - pref[i][j]);
                    dp[i][j] = max(dp[i][j], dp[i - 1][k] + val);
                }else{
                    for(int l = 0; l < 10; ++l){
                        if(k >= j){
                            val = pref[i][k] - pref[i][j];
                            dp[i][j] = max(dp[i][j], dp[i - 1][k] + val);
                        }else{
                            if(l <= k){
                                val = pref[i - 1][j] - pref[i - 1][k] + pref[i - 2][k] - pref[i - 2][l];
                                dp[i][j] = max(dp[i][j], dp[i - 2][l] + val);
                            }else{
                                val = pref[i - 1][max(j, l)] - pref[i - 1][k];
                                dp[i][j] = max(dp[i][j], dp[i - 2][l] + val);
                            }
                        }
                    }
                }
                if(i >= 2){
                    val = pref[i - 1][max(j, k)];
                    dp[i][j] = max(dp[i][j], dp[i - 2][k] + val);
                }
                if(i >= 3){
                    val = pref[i - 1][j] + pref[i - 2][k];
                    dp[i][j] = max(dp[i][j], dp[i - 3][k] + val);
                }
            }
        }
    }
    return dp[n][0];
}   

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:31:17: warning: unused variable 'p' [-Wunused-variable]
   31 |             int p = 0;
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 3512 KB Output is correct
2 Correct 31 ms 4300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 92 ms 11104 KB Output is correct
6 Correct 88 ms 11212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 304 KB Output is correct
2 Correct 48 ms 8992 KB Output is correct
3 Correct 64 ms 10840 KB Output is correct
4 Correct 23 ms 3536 KB Output is correct
5 Correct 33 ms 4288 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 25 ms 5736 KB Output is correct
13 Correct 29 ms 6732 KB Output is correct
14 Correct 26 ms 5736 KB Output is correct
15 Correct 30 ms 6356 KB Output is correct
16 Correct 25 ms 5672 KB Output is correct
17 Correct 27 ms 6220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 201 ms 23780 KB Output is correct
3 Incorrect 191 ms 23652 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '25547296794624'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Incorrect 1 ms 340 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '239474674534'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Incorrect 1 ms 340 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '239474674534'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 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 1 ms 212 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Incorrect 1 ms 340 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '239474674534'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 201 ms 23780 KB Output is correct
3 Incorrect 191 ms 23652 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '25547296794624'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 3512 KB Output is correct
2 Correct 31 ms 4300 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 92 ms 11104 KB Output is correct
6 Correct 88 ms 11212 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 48 ms 8992 KB Output is correct
9 Correct 64 ms 10840 KB Output is correct
10 Correct 23 ms 3536 KB Output is correct
11 Correct 33 ms 4288 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 25 ms 5736 KB Output is correct
19 Correct 29 ms 6732 KB Output is correct
20 Correct 26 ms 5736 KB Output is correct
21 Correct 30 ms 6356 KB Output is correct
22 Correct 25 ms 5672 KB Output is correct
23 Correct 27 ms 6220 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 201 ms 23780 KB Output is correct
26 Incorrect 191 ms 23652 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '25547296794624'
27 Halted 0 ms 0 KB -