답안 #720843

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
720843 2023-04-09T14:01:43 Z HaiHoang 메기 농장 (IOI22_fish) C++17
53 / 100
523 ms 888128 KB
#include <bits/stdc++.h>

using namespace std;

#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()

#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it)

template <class U, class V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; }
template <class U, class V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; }
const int MAXN = 1e5 + 5;
namespace sub1 {
    bool check(int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
        REP(i, M) if(X[i] % 2 == 1) return false;
        return true;
    }
    long long Main(int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
        long long ans = 0;
        REP(i, M) ans += W[i];
        return ans;
    }
}
namespace sub2 {
    long long pre[2][MAXN];
    bool check(int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
        REP(i, M) if(X[i] > 1) return false;
        return true;
    }
    long long Main(int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
        long long ans = 0;
        REP(i, M) pre[X[i]][Y[i]] += W[i];
        FOR(i, 1, N - 1) {
            pre[0][i] += pre[0][i - 1];
            pre[1][i] += pre[1][i - 1];
        }
        ans = max(pre[0][N - 1], pre[1][N - 1]);
        if(N == 2) return ans;
        REP(i, N) {
            long long val = pre[1][N - 1] - pre[1][i];
            maximize(ans, val + pre[0][i]);
        }
        return ans;
    }
}
namespace sub3 {
    bool check (int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
        REP(i, M) if(Y[i]) return false;
        return true;
    }
    long long dp[MAXN][2][2], a[MAXN];
    long long Main(int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
        long long ans = 0;
        REP(i, M) a[X[i] + 1] += W[i];
        FOR(i, 1, N) {
            dp[i][1][0] = max({dp[i - 1][0][0] + a[i - 1] + a[i + 1], dp[i - 1][0][1] + a[i + 1], dp[i - 1][1][0] - a[i] + a[i + 1]});
            dp[i][0][0] = max(dp[i - 1][0][0], dp[i - 1][0][1]);
            dp[i][0][1] = dp[i - 1][1][0];
            maximize(ans, dp[i][1][0]);
            maximize(ans, dp[i][0][0]);
            maximize(ans, dp[i][0][1]);
            // cout << dp[i][1][0] << " \n"[i == N];
        }
        return ans;
    }
}
namespace sub4 {
    bool check (int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
        if(N > 300) return false;
        REP(i, M) if(Y[i] > 8) return false;
        return true;
    }
    long long dp[MAXN][10][10], pre[MAXN][10];
    long long get(int x, int l, int r) { if(l > r) return 0; return pre[x][r] - pre[x][l - 1]; }
    long long Main(int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
        long long ans = 0;
        int lim = min(9, N + 1);
        REP(i, M) pre[X[i] + 1][Y[i] + 1] += W[i];
        FOR(i, 1, N) FOR(j, 1, lim - 1) pre[i][j] += pre[i][j - 1];
        FOR(i, 2, N) REP(l1, lim) REP(l2, lim) REP(l3, lim) {
            long long val = 0, val2 = 0;
            if(l2 < l3) val = get(i - 1, l2 + 1, l3);
            else val = get(i, l3 + 1, l2);
            if(l1 > l2 && l2 < l3) {
                if(l1 < l3) maximize(dp[i][l2][l3], dp[i - 1][l1][l2] + get(i - 1, l1 + 1, l3));
                else maximize(dp[i][l2][l3], dp[i - 1][l1][l2]);
            }
            else maximize(dp[i][l2][l3], dp[i - 1][l1][l2] + val);
            maximize(ans, dp[i][l2][l3]);

        }
        return ans;
    }
}
namespace sub5 {
    const int MAX = 305;
    long long dp[MAX][MAX][MAX], Max[3][MAX][MAX][MAX];
    long long pre[MAX][MAX];
    long long get(int i, int l, int r) { if(r < l) return 0; return pre[i][r] - pre[i][l - 1]; }
    long long Main(int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
        long long ans = 0;
        memset(Max, -0x3f, sizeof Max);
        REP(i, M) pre[X[i] + 1][Y[i] + 1] += W[i];
        FOR(i, 1, N) FOR(j, 1, N) pre[i][j] += pre[i][j - 1];
        REP(i, 3) memset(Max[i][1], 0, sizeof Max[i][1]);
        FOR(i, 2, N) {
            REP(l1, N + 1) REP(l2, N + 1) {
                if(l1 < l2) dp[i][l1][l2] = Max[0][i - 1][l1][l1] + get(i - 1, l1 + 1, l2);
                else dp[i][l1][l2] = Max[0][i - 1][N][l1] + get(i, l2 + 1, l1);
                if(l1 < l2) {
                    maximize(dp[i][l1][l2], Max[1][i - 1][l2][l1]);
                    // maximize(dp[i][l1][l2], Max[2][i - 1][l2][l1] + get(i - 1, 1, l2));
                }
                maximize(ans, dp[i][l1][l2]);
                maximize(Max[0][i][l1][l2], dp[i][l1][l2]);
                maximize(Max[2][i][l1][l2], dp[i][l1][l2] - get(i, 1, max(l1, l2)));
                if(l1 > 0) {
                    maximize(Max[0][i][l1][l2], Max[0][i][l1 - 1][l2]);
                    maximize(Max[2][i][l1][l2], Max[2][i][l1 - 1][l2]);
                }
            }
            FORD(l1, N, 0) FORD(l2, l1, 0) {
                maximize(Max[1][i][l1][l2], dp[i][l1][l2]);
                if(l1 < N) maximize(Max[1][i][l1][l2], Max[1][i][l1 + 1][l2]);
            }
        }
        // cout << dp[5][0][4] << '\n';
        // cout << Max[2][2][5][3] << '\n';
        return ans;
    }
}
long long max_weights(int N, int M, vector <int> X, vector <int> Y, vector <int> W) {
    if(N <= 300) return sub5::Main(N, M, X, Y, W);
    if(sub1::check(N, M, X, Y, W)) return sub1::Main(N, M, X, Y, W);
    if(sub2::check(N, M, X, Y, W)) return sub2::Main(N, M, X, Y, W);
    if(sub3::check(N, M, X, Y, W)) return sub3::Main(N, M, X, Y, W);
    if(sub4::check(N, M, X, Y, W)) return sub4::Main(N, M, X, Y, W);
    return 0;
}

Compilation message

fish.cpp: In function 'long long int sub4::Main(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:85:32: warning: unused variable 'val2' [-Wunused-variable]
   85 |             long long val = 0, val2 = 0;
      |                                ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 4556 KB Output is correct
2 Correct 32 ms 5588 KB Output is correct
3 Correct 1 ms 232 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 94 ms 15672 KB Output is correct
6 Correct 94 ms 15756 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 385 ms 666620 KB Output is correct
2 Correct 49 ms 10216 KB Output is correct
3 Correct 61 ms 12300 KB Output is correct
4 Correct 24 ms 4536 KB Output is correct
5 Correct 29 ms 5568 KB Output is correct
6 Correct 270 ms 666576 KB Output is correct
7 Correct 257 ms 666484 KB Output is correct
8 Correct 276 ms 666560 KB Output is correct
9 Correct 273 ms 666500 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 28 ms 5908 KB Output is correct
13 Correct 31 ms 7072 KB Output is correct
14 Correct 26 ms 5936 KB Output is correct
15 Correct 33 ms 6636 KB Output is correct
16 Correct 25 ms 5932 KB Output is correct
17 Correct 28 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 18 ms 6656 KB Output is correct
4 Correct 13 ms 5740 KB Output is correct
5 Correct 34 ms 9328 KB Output is correct
6 Correct 25 ms 8664 KB Output is correct
7 Correct 30 ms 9228 KB Output is correct
8 Correct 30 ms 9244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 247 ms 666560 KB Output is correct
2 Correct 245 ms 666812 KB Output is correct
3 Correct 247 ms 666552 KB Output is correct
4 Correct 239 ms 666504 KB Output is correct
5 Correct 240 ms 666588 KB Output is correct
6 Correct 266 ms 666500 KB Output is correct
7 Correct 238 ms 666572 KB Output is correct
8 Correct 269 ms 666628 KB Output is correct
9 Correct 310 ms 721128 KB Output is correct
10 Correct 516 ms 883360 KB Output is correct
11 Correct 296 ms 721128 KB Output is correct
12 Correct 471 ms 883412 KB Output is correct
13 Correct 255 ms 680384 KB Output is correct
14 Correct 480 ms 883344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 247 ms 666560 KB Output is correct
2 Correct 245 ms 666812 KB Output is correct
3 Correct 247 ms 666552 KB Output is correct
4 Correct 239 ms 666504 KB Output is correct
5 Correct 240 ms 666588 KB Output is correct
6 Correct 266 ms 666500 KB Output is correct
7 Correct 238 ms 666572 KB Output is correct
8 Correct 269 ms 666628 KB Output is correct
9 Correct 310 ms 721128 KB Output is correct
10 Correct 516 ms 883360 KB Output is correct
11 Correct 296 ms 721128 KB Output is correct
12 Correct 471 ms 883412 KB Output is correct
13 Correct 255 ms 680384 KB Output is correct
14 Correct 480 ms 883344 KB Output is correct
15 Correct 463 ms 883328 KB Output is correct
16 Correct 258 ms 680420 KB Output is correct
17 Correct 523 ms 885692 KB Output is correct
18 Correct 488 ms 885688 KB Output is correct
19 Correct 488 ms 885688 KB Output is correct
20 Correct 478 ms 885688 KB Output is correct
21 Correct 478 ms 885612 KB Output is correct
22 Correct 518 ms 888128 KB Output is correct
23 Correct 496 ms 883756 KB Output is correct
24 Correct 482 ms 885068 KB Output is correct
25 Correct 463 ms 883404 KB Output is correct
26 Correct 488 ms 883704 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 247 ms 666560 KB Output is correct
2 Correct 245 ms 666812 KB Output is correct
3 Correct 247 ms 666552 KB Output is correct
4 Correct 239 ms 666504 KB Output is correct
5 Correct 240 ms 666588 KB Output is correct
6 Correct 266 ms 666500 KB Output is correct
7 Correct 238 ms 666572 KB Output is correct
8 Correct 269 ms 666628 KB Output is correct
9 Correct 310 ms 721128 KB Output is correct
10 Correct 516 ms 883360 KB Output is correct
11 Correct 296 ms 721128 KB Output is correct
12 Correct 471 ms 883412 KB Output is correct
13 Correct 255 ms 680384 KB Output is correct
14 Correct 480 ms 883344 KB Output is correct
15 Correct 463 ms 883328 KB Output is correct
16 Correct 258 ms 680420 KB Output is correct
17 Correct 523 ms 885692 KB Output is correct
18 Correct 488 ms 885688 KB Output is correct
19 Correct 488 ms 885688 KB Output is correct
20 Correct 478 ms 885688 KB Output is correct
21 Correct 478 ms 885612 KB Output is correct
22 Correct 518 ms 888128 KB Output is correct
23 Correct 496 ms 883756 KB Output is correct
24 Correct 482 ms 885068 KB Output is correct
25 Correct 463 ms 883404 KB Output is correct
26 Correct 488 ms 883704 KB Output is correct
27 Incorrect 1 ms 324 KB 1st lines differ - on the 1st token, expected: '2999', found: '0'
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 18 ms 6656 KB Output is correct
4 Correct 13 ms 5740 KB Output is correct
5 Correct 34 ms 9328 KB Output is correct
6 Correct 25 ms 8664 KB Output is correct
7 Correct 30 ms 9228 KB Output is correct
8 Correct 30 ms 9244 KB Output is correct
9 Incorrect 28 ms 5176 KB 1st lines differ - on the 1st token, expected: '99999', found: '0'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 4556 KB Output is correct
2 Correct 32 ms 5588 KB Output is correct
3 Correct 1 ms 232 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 94 ms 15672 KB Output is correct
6 Correct 94 ms 15756 KB Output is correct
7 Correct 385 ms 666620 KB Output is correct
8 Correct 49 ms 10216 KB Output is correct
9 Correct 61 ms 12300 KB Output is correct
10 Correct 24 ms 4536 KB Output is correct
11 Correct 29 ms 5568 KB Output is correct
12 Correct 270 ms 666576 KB Output is correct
13 Correct 257 ms 666484 KB Output is correct
14 Correct 276 ms 666560 KB Output is correct
15 Correct 273 ms 666500 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 28 ms 5908 KB Output is correct
19 Correct 31 ms 7072 KB Output is correct
20 Correct 26 ms 5936 KB Output is correct
21 Correct 33 ms 6636 KB Output is correct
22 Correct 25 ms 5932 KB Output is correct
23 Correct 28 ms 6492 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 3412 KB Output is correct
26 Correct 18 ms 6656 KB Output is correct
27 Correct 13 ms 5740 KB Output is correct
28 Correct 34 ms 9328 KB Output is correct
29 Correct 25 ms 8664 KB Output is correct
30 Correct 30 ms 9228 KB Output is correct
31 Correct 30 ms 9244 KB Output is correct
32 Correct 247 ms 666560 KB Output is correct
33 Correct 245 ms 666812 KB Output is correct
34 Correct 247 ms 666552 KB Output is correct
35 Correct 239 ms 666504 KB Output is correct
36 Correct 240 ms 666588 KB Output is correct
37 Correct 266 ms 666500 KB Output is correct
38 Correct 238 ms 666572 KB Output is correct
39 Correct 269 ms 666628 KB Output is correct
40 Correct 310 ms 721128 KB Output is correct
41 Correct 516 ms 883360 KB Output is correct
42 Correct 296 ms 721128 KB Output is correct
43 Correct 471 ms 883412 KB Output is correct
44 Correct 255 ms 680384 KB Output is correct
45 Correct 480 ms 883344 KB Output is correct
46 Correct 463 ms 883328 KB Output is correct
47 Correct 258 ms 680420 KB Output is correct
48 Correct 523 ms 885692 KB Output is correct
49 Correct 488 ms 885688 KB Output is correct
50 Correct 488 ms 885688 KB Output is correct
51 Correct 478 ms 885688 KB Output is correct
52 Correct 478 ms 885612 KB Output is correct
53 Correct 518 ms 888128 KB Output is correct
54 Correct 496 ms 883756 KB Output is correct
55 Correct 482 ms 885068 KB Output is correct
56 Correct 463 ms 883404 KB Output is correct
57 Correct 488 ms 883704 KB Output is correct
58 Incorrect 1 ms 324 KB 1st lines differ - on the 1st token, expected: '2999', found: '0'
59 Halted 0 ms 0 KB -