답안 #837870

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
837870 2023-08-25T19:17:48 Z Dremix10 메기 농장 (IOI22_fish) C++17
58 / 100
1000 ms 2097152 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
const int N = 3e5+5;
const int MOD = 1e9+7;
const ll INF = 1e18+5;
#ifdef dremix
    #define p(x) cerr<<#x<<" = "<<x<<endl;
    #define pv(x) cerr<<#x<<" = {";for(auto v : x)cerr<<v<<", ";cerr<<"}"<<endl;
#else
    #define p(x) {}
    #define pv(x) {}
#endif



long long max_weights(int n, int m, vector<int> x, vector<int> y, vector<int> w) {
    /// pier optimal options are below each fish in each column or full column
    /// dp[i][j][k], I am at column i with the following status:
    /// at column (i-1) the pier was built below fish j and above that the fish caught were k

    int i,j,k;

    vector<vector<pi> > col(n,vector<pi>());
    //p(1)
    for(i=0;i<m;i++){
        col[x[i]].push_back({y[i],w[i]});
    }

    for(i=0;i<n;i++){
        sort(all(col[i]));
    }

    vector<vector<vector<ll> > > dp(n,vector<vector<ll> >());
    vector<vector<ll> > best(n,vector<ll>()),eaten(n,vector<ll>());
    vector<ll> ans(n,-INF);
    //p(2)

    for(i=0;i<n;i++){
        //p(i) 
        int sz = col[i].size();
        dp[i].assign(sz+1,vector<ll>());
        best[i].assign(sz+1,-INF);
        eaten[i].assign(sz+1,-INF);
           
        for(j=0;j<=sz;j++){
            dp[i][j].assign(sz+1-j,-INF);
        }
    }

    /// starting at i = 0 (base case)

    int sz = col[0].size();
    //p(3)
    ans[0] = 0;
    for(j=0;j<=sz;j++){
        dp[0][j][0] = 0;
        best[0][j] = 0;
        eaten[0][j] = 0;
    }
    //p(4)
    p("go")
    for(i=1;i<n;i++){
        /// at column i with sz fish
        int sz = col[i].size();
        int sz1 = col[i-1].size();
        
        ll tot = 0;
        int p1 = 0;
        ans[i] = max(ans[i],ans[i-1]);

        for(j=0;j<sz;j++){
            p(j)
            int h = col[i][j].F-1;
            /// build pier up to h

            /// 2 cases: 

            /// (i-1) catches my fish

            int idx = j;
            ll sum = 0;
            best[i][j] = max(best[i][j],ans[i-1]);
            eaten[i][j] = max(eaten[i][j],ans[i-1]);
            

            for(k=0;k<sz1;k++){
                while(idx < sz && col[i][idx].F <= col[i-1][k].F-1){
                    sum += col[i][idx].S;
                    idx++;
                }
                ll temp = best[i-1][k] + sum;
                //p(temp)
                best[i][j] = max(best[i][j],temp);
                eaten[i][idx] = max(eaten[i][idx],temp);
                ans[i] = max(ans[i],temp);
            }

            /// case of full col
            while(idx < sz){
                sum += col[i][idx].S;
                idx++;
            }
            ll temp = best[i-1][k] + sum;
            best[i][j] = max(best[i][j],temp);
            eaten[i][idx] = max(eaten[i][idx],temp);
            ans[i] = max(ans[i],temp);


            /// I catch fish from (i-1)
            while(p1 < sz1 && col[i-1][p1].F <= h){
                tot += col[i-1][p1].S;
                p1++;
            }

            // I can get up to fish (p1-1)
            ll temp2 = tot;
            //p(j)

            for(k=0;k<p1;k++){
                /// I will get fish from {k,p1-1} (temp)

                /// i need best dp[i-1][o][oo] with o+oo == k
                //p(k)
                //p(temp2)
                ll temp = eaten[i-1][k] + temp2;
                //p(temp)
                best[i][j] = max(best[i][j],temp);
                eaten[i][j] = max(eaten[i][j],temp);
                ans[i] = max(ans[i],temp);

                temp2 -= col[i-1][k].S;
            }

        }

        /// case of full col
            
            /// build pier up to h
            best[i][j] = max(best[i][j],ans[i-1]);
            eaten[i][j] = max(eaten[i][j],ans[i-1]);
            /// 2 cases
            /// I catch fish from (i-1)
            while(p1 < sz1){
                tot += col[i-1][p1].S;
                p1++;
            }

            // I can get up to fish (p1-1)
            ll temp2 = tot;
            //p(temp2)
            //p(p1)
            for(k=0;k<p1;k++){
                /// I will get fish from {k,p1-1} (temp)

                /// i need best dp[i-1][o][oo] with o+oo == k
                
                ll temp = eaten[i-1][k] + temp2;
                //p(temp)
                best[i][j] = max(best[i][j],temp);
                eaten[i][j] = max(eaten[i][j],temp);
                ans[i] = max(ans[i],temp);

                temp2 -= col[i-1][k].S;
            }
        pv(best[i])
        pv(eaten[i])

    }

    // from last col
    pv(ans)

    return ans[n-1];
}
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1120 ms 1903604 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 870 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 22996 KB Output is correct
2 Correct 26 ms 22948 KB Output is correct
3 Correct 50 ms 26956 KB Output is correct
4 Correct 45 ms 27728 KB Output is correct
5 Correct 84 ms 36272 KB Output is correct
6 Correct 70 ms 35656 KB Output is correct
7 Correct 76 ms 36172 KB Output is correct
8 Correct 74 ms 36312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 980 KB Output is correct
17 Correct 82 ms 48524 KB Output is correct
18 Correct 94 ms 53084 KB Output is correct
19 Correct 60 ms 32004 KB Output is correct
20 Correct 57 ms 31908 KB Output is correct
21 Correct 59 ms 31956 KB Output is correct
22 Correct 197 ms 116556 KB Output is correct
23 Correct 6 ms 2388 KB Output is correct
24 Correct 31 ms 15572 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 6 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 592 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 980 KB Output is correct
17 Correct 82 ms 48524 KB Output is correct
18 Correct 94 ms 53084 KB Output is correct
19 Correct 60 ms 32004 KB Output is correct
20 Correct 57 ms 31908 KB Output is correct
21 Correct 59 ms 31956 KB Output is correct
22 Correct 197 ms 116556 KB Output is correct
23 Correct 6 ms 2388 KB Output is correct
24 Correct 31 ms 15572 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 6 ms 2260 KB Output is correct
27 Correct 3 ms 1364 KB Output is correct
28 Correct 894 ms 532368 KB Output is correct
29 Runtime error 814 ms 2097152 KB Execution killed with signal 9
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 22996 KB Output is correct
2 Correct 26 ms 22948 KB Output is correct
3 Correct 50 ms 26956 KB Output is correct
4 Correct 45 ms 27728 KB Output is correct
5 Correct 84 ms 36272 KB Output is correct
6 Correct 70 ms 35656 KB Output is correct
7 Correct 76 ms 36172 KB Output is correct
8 Correct 74 ms 36312 KB Output is correct
9 Correct 72 ms 35976 KB Output is correct
10 Correct 55 ms 22652 KB Output is correct
11 Correct 111 ms 45264 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 27 ms 22996 KB Output is correct
19 Correct 28 ms 22996 KB Output is correct
20 Correct 27 ms 22996 KB Output is correct
21 Correct 28 ms 22996 KB Output is correct
22 Correct 82 ms 35176 KB Output is correct
23 Correct 116 ms 45264 KB Output is correct
24 Correct 120 ms 45796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1120 ms 1903604 KB Time limit exceeded
2 Halted 0 ms 0 KB -