답안 #906702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
906702 2024-01-14T19:00:35 Z vjudge1 메기 농장 (IOI22_fish) C++17
53 / 100
364 ms 19792 KB
#include "fish.h"

#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

#include<bits/stdc++.h>
#include<math.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
#define FD(i, r, l) for(ll i = r; i > (l); --i)

#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = l; i < (r); ++i)

#define NN 310

ll grid[NN][NN];
ll n;

ll dp1[NN][NN];
ll noreq(ll, ll); // no request fishies, so len == prev wall. 

ll dp2[NN][NN];
ll req(ll, ll); 

// previous column did NOT request any right fishies here
// so we simply have a free wall to attach to 
ll noreq(ll i, ll len) {
    // assert(len == 0 or len == n);
    if (i == n) return 0;
    auto &DP = dp1[i][len];
    if (!~DP) {
        DP = noreq(i+1, n); // no restrictions so build big wall.

        F(nlen, 0, n+1) DP = max(DP, req(i, nlen)); // basically can set up any wall here before taking right fishes

        ll lsum = 0;
        F(j, 0, len) {
            lsum += grid[i][j];
        }
        DP = max(DP, lsum + noreq(i+1, 0));
        {
            ll tsum = lsum;
            F(j, 0, len) {
                tsum -= grid[i][j];
                DP = max(DP, tsum + noreq(i+1, j+1));
            }
        }


        F(covering, len, n) {
            // not lsum naymore jsut cum sum
            lsum += grid[i][covering];
            DP = max(DP, lsum + req(i+1, covering + 1));
        }

    }   
    return DP;   
}


// previous column requested right fishes here;
// so len == min bound on wall (we cannot take anything below len)

ll req(ll i, ll len) {
    if (i == n) return len == 0 ? 0 : -9e18; // i should need 0 fishes here
    auto &DP = dp2[i][len];
    if (!~DP) {
        // note that we cannot request any left fishes here.
        DP = noreq(i+1, n);  // if we don't request ANY fish here, just go up to max 

        ll sm = 0;
        F(covering, len, n) {
            sm += grid[i][covering];
            DP = max(DP, sm + req(i+1, covering + 1));
        }
    }   
    return DP;
}

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
    ll rans = -1;

    if (N <= 300) {
        memset(dp1, -1, sizeof dp1);
        memset(dp2, -1, sizeof dp2);
        
        n = N;
        memset(grid, 0, sizeof grid);
        F(i, 0, M) grid[X[i]][Y[i]] = W[i];
        
        rans = noreq(0, 0);          
    }

    bool case1 = 1;
    bool case2 = 1;
    bool case3 = 1;
    F(i, 0, M) case1 &= X[i]%2 == 0;
    F(i, 0, M) case2 &= X[i] <= 1;
    F(i, 0, M) case3 &= Y[i] == 0;
    
    if (case1) {
        return accumulate(A(W), 0ll);
    } else if (case2) {
        ll c[2] = {};
        map<pl, ll> points;
        F(i, 0, M) {
            c[X[i]] += W[i];
            points[{X[i], Y[i]}] = W[i];
        }
        
        if (N == 2) {
            return max(c[0], c[1]);
        }
        ll tans = max(c[0], c[1]);
        ll tsum = c[1];
        F(i, 0, N) {
            tsum -= points[{1, i}];
            tsum += points[{0, i}];
            tans = max(tans, tsum);
        }

        return tans;
    } else if (case3) {
        n = N;
        vl grid(n);
        F(i, 0, M) grid[X[i]] = W[i];
        vector<vl> dp(n+10, vl(3, -1));
        auto rec = [&](auto &&self, ll i, ll f) -> ll {
            if (i > n) return -1e18;
            if (i >= n) return 0;
            auto &DP = dp[i][f];
            if (!~DP) {
                DP = self(self, i+1, 1);
                if (f) DP = max(DP, grid[i] + self(self, i+1, 0));
                DP = max(DP, grid[i] + self(self, i+2, 1));
            }
            return DP;
        };
        // cout << rec(rec, 0, 0) << ' ' << rans << endl;
        // assert(rec(rec, 0, 0) == rans);
        return rec(rec, 0, 0);
    }

    return rans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 2140 KB Output is correct
2 Correct 22 ms 2652 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 65 ms 7280 KB Output is correct
6 Correct 71 ms 7280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 133 ms 15396 KB Output is correct
3 Correct 179 ms 17492 KB Output is correct
4 Correct 18 ms 2136 KB Output is correct
5 Correct 22 ms 2648 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 1 ms 2652 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 74 ms 13624 KB Output is correct
13 Correct 79 ms 15308 KB Output is correct
14 Correct 64 ms 13396 KB Output is correct
15 Correct 95 ms 15184 KB Output is correct
16 Correct 63 ms 13428 KB Output is correct
17 Correct 72 ms 14920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 14 ms 15704 KB Output is correct
3 Correct 24 ms 16476 KB Output is correct
4 Correct 21 ms 17244 KB Output is correct
5 Correct 34 ms 19792 KB Output is correct
6 Correct 32 ms 19028 KB Output is correct
7 Correct 34 ms 19540 KB Output is correct
8 Correct 35 ms 19536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 46 ms 2652 KB Output is correct
10 Correct 326 ms 2648 KB Output is correct
11 Correct 42 ms 2648 KB Output is correct
12 Correct 324 ms 2648 KB Output is correct
13 Correct 6 ms 2652 KB Output is correct
14 Correct 340 ms 2900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 46 ms 2652 KB Output is correct
10 Correct 326 ms 2648 KB Output is correct
11 Correct 42 ms 2648 KB Output is correct
12 Correct 324 ms 2648 KB Output is correct
13 Correct 6 ms 2652 KB Output is correct
14 Correct 340 ms 2900 KB Output is correct
15 Correct 329 ms 2776 KB Output is correct
16 Correct 7 ms 2652 KB Output is correct
17 Correct 364 ms 3924 KB Output is correct
18 Correct 345 ms 3840 KB Output is correct
19 Correct 340 ms 3836 KB Output is correct
20 Correct 334 ms 3672 KB Output is correct
21 Correct 342 ms 3840 KB Output is correct
22 Correct 341 ms 4892 KB Output is correct
23 Correct 330 ms 2976 KB Output is correct
24 Correct 330 ms 3416 KB Output is correct
25 Correct 330 ms 2800 KB Output is correct
26 Correct 324 ms 2908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Correct 1 ms 2652 KB Output is correct
4 Correct 1 ms 2652 KB Output is correct
5 Correct 1 ms 2652 KB Output is correct
6 Correct 1 ms 2652 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 46 ms 2652 KB Output is correct
10 Correct 326 ms 2648 KB Output is correct
11 Correct 42 ms 2648 KB Output is correct
12 Correct 324 ms 2648 KB Output is correct
13 Correct 6 ms 2652 KB Output is correct
14 Correct 340 ms 2900 KB Output is correct
15 Correct 329 ms 2776 KB Output is correct
16 Correct 7 ms 2652 KB Output is correct
17 Correct 364 ms 3924 KB Output is correct
18 Correct 345 ms 3840 KB Output is correct
19 Correct 340 ms 3836 KB Output is correct
20 Correct 334 ms 3672 KB Output is correct
21 Correct 342 ms 3840 KB Output is correct
22 Correct 341 ms 4892 KB Output is correct
23 Correct 330 ms 2976 KB Output is correct
24 Correct 330 ms 3416 KB Output is correct
25 Correct 330 ms 2800 KB Output is correct
26 Correct 324 ms 2908 KB Output is correct
27 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '2999', found: '-1'
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 14 ms 15704 KB Output is correct
3 Correct 24 ms 16476 KB Output is correct
4 Correct 21 ms 17244 KB Output is correct
5 Correct 34 ms 19792 KB Output is correct
6 Correct 32 ms 19028 KB Output is correct
7 Correct 34 ms 19540 KB Output is correct
8 Correct 35 ms 19536 KB Output is correct
9 Incorrect 22 ms 3932 KB 1st lines differ - on the 1st token, expected: '99999', found: '-1'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 2140 KB Output is correct
2 Correct 22 ms 2652 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 65 ms 7280 KB Output is correct
6 Correct 71 ms 7280 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 133 ms 15396 KB Output is correct
9 Correct 179 ms 17492 KB Output is correct
10 Correct 18 ms 2136 KB Output is correct
11 Correct 22 ms 2648 KB Output is correct
12 Correct 1 ms 2652 KB Output is correct
13 Correct 1 ms 2652 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 1 ms 2652 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 74 ms 13624 KB Output is correct
19 Correct 79 ms 15308 KB Output is correct
20 Correct 64 ms 13396 KB Output is correct
21 Correct 95 ms 15184 KB Output is correct
22 Correct 63 ms 13428 KB Output is correct
23 Correct 72 ms 14920 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 14 ms 15704 KB Output is correct
26 Correct 24 ms 16476 KB Output is correct
27 Correct 21 ms 17244 KB Output is correct
28 Correct 34 ms 19792 KB Output is correct
29 Correct 32 ms 19028 KB Output is correct
30 Correct 34 ms 19540 KB Output is correct
31 Correct 35 ms 19536 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 1 ms 2652 KB Output is correct
40 Correct 46 ms 2652 KB Output is correct
41 Correct 326 ms 2648 KB Output is correct
42 Correct 42 ms 2648 KB Output is correct
43 Correct 324 ms 2648 KB Output is correct
44 Correct 6 ms 2652 KB Output is correct
45 Correct 340 ms 2900 KB Output is correct
46 Correct 329 ms 2776 KB Output is correct
47 Correct 7 ms 2652 KB Output is correct
48 Correct 364 ms 3924 KB Output is correct
49 Correct 345 ms 3840 KB Output is correct
50 Correct 340 ms 3836 KB Output is correct
51 Correct 334 ms 3672 KB Output is correct
52 Correct 342 ms 3840 KB Output is correct
53 Correct 341 ms 4892 KB Output is correct
54 Correct 330 ms 2976 KB Output is correct
55 Correct 330 ms 3416 KB Output is correct
56 Correct 330 ms 2800 KB Output is correct
57 Correct 324 ms 2908 KB Output is correct
58 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '2999', found: '-1'
59 Halted 0 ms 0 KB -