답안 #626874

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
626874 2022-08-11T22:16:36 Z ionan6ix 메기 농장 (IOI22_fish) C++17
18 / 100
81 ms 10048 KB
#include "fish.h"

#include <vector>
#include<algorithm>
using namespace std;

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {

    bool flag = true;

    for(auto it:X)
        if(it%2)
        {
            flag = false;
            break;
        }

    if(flag)
    {
        long long sol = 0;
        for(auto it:W)
            sol+=it;

        return sol;
    }

    flag = true;

    for(auto it:X)
        if(it>1)
        {
            flag = false;
            break;
        }

    if(flag)
    {
        std::vector<pair<int,int> > y0;
        std::vector<pair<int,int> > y1;

        int sz = X.size();

        for(int i=0;i<M;i++)
            if(X[i]==0) y0.emplace_back(Y[i],W[i]);
            else y1.emplace_back(Y[i],W[i]);

        std::sort(y0.begin(),y0.end());
        std::sort(y1.begin(),y1.end());

        if(N==2)
        {
            //efectiv...

            long long sum0=0LL;
            long long sum1=0LL;

            for(auto it:y0)
                sum0+=1LL*it.second;

            for(auto it:y1)
                sum1+=1LL*it.second;

            return max(sum0,sum1);
        }
        long long sol = 0LL;
        long long sum = 0LL;

        for(auto it:y1)
            sum += 1LL*it.second;

        sol = sum;

        /**
         * Pana la un anumit punct luam din 0, apoi din 1
         */

        int pnt0 = -1;
        int pnt1 = 0;
        long long sum0 = 0;
        for(int i=0;i<(int)y0.size();i++)
        {
            pnt0++;
            sum0 += 1LL * y0[i].second;

            while(pnt1<(int)y1.size() && y1[pnt1].first<=y0[i].first)
            {
                sum -= 1LL * y1[pnt1].second;
                pnt1++;
            }
            sol = max(sol,sum+sum0);
        }
        sol = max(sol,sum+sum0);
        sum0 = 0LL;
        for(auto it:y0)
            sum0+=1LL*it.second;

        sol = max(sol,sum0);


        return sol;
    }

    flag = true;

    for(auto it:Y)
        if(it!=0)
        {
            flag = false;
            break;
        }

    if(flag)
    {

        vector<vector<long long> > dp;

        dp.resize(N+5);

        for(int i = 0;i<N;i++)
            dp[i].resize(4);



        vector<int> repr;
        repr.resize(N+5);

        for(int i = 0;i<M;i++)
            repr[X[i]] = W[i];

        dp[1][0] = 0;
        dp[1][1] = repr[0];
        dp[1][2] = repr[1];
        dp[1][3] = 0;

        for(int i=2;i<N;i++)
        {
            dp[i][0] = max(max(dp[i-2][0],dp[i-2][2]),max(dp[i-2][1],dp[i-2][3])+1LL*repr[i-1]);
            dp[i][1] = max(max(dp[i-2][0],dp[i-2][2])+1LL*repr[i-1],max(dp[i-2][1],dp[i-2][3])+1LL*repr[i-1]);
            dp[i][2] = max(max(dp[i-2][0]+1LL*repr[i-2]+1LL*repr[i],dp[i-2][2]+1LL*repr[i]),max(dp[i-2][1]+1LL*repr[i],dp[i-2][3]+1LL*repr[i]));
            dp[i][3] = max(max(dp[i-2][0]+1LL*repr[i-2],dp[i-2][2]),max(dp[i-2][1],dp[i-2][3]));
        }
        return max(max(dp[N-1][0],dp[N-1][1]),max(dp[N-1][2],dp[N-1][3]));
    }
    return 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:42:13: warning: unused variable 'sz' [-Wunused-variable]
   42 |         int sz = X.size();
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 2132 KB Output is correct
2 Correct 29 ms 2616 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 79 ms 7260 KB Output is correct
6 Correct 81 ms 7248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 63 ms 5672 KB Output is correct
3 Correct 69 ms 6728 KB Output is correct
4 Correct 21 ms 2148 KB Output is correct
5 Correct 27 ms 2620 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 28 ms 3296 KB Output is correct
13 Correct 36 ms 3764 KB Output is correct
14 Correct 27 ms 3064 KB Output is correct
15 Correct 32 ms 3536 KB Output is correct
16 Correct 28 ms 3164 KB Output is correct
17 Correct 32 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 9 ms 7636 KB Output is correct
3 Correct 21 ms 8148 KB Output is correct
4 Correct 17 ms 8532 KB Output is correct
5 Correct 35 ms 10044 KB Output is correct
6 Correct 28 ms 10048 KB Output is correct
7 Correct 32 ms 10048 KB Output is correct
8 Correct 32 ms 9964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 9 ms 7636 KB Output is correct
3 Correct 21 ms 8148 KB Output is correct
4 Correct 17 ms 8532 KB Output is correct
5 Correct 35 ms 10044 KB Output is correct
6 Correct 28 ms 10048 KB Output is correct
7 Correct 32 ms 10048 KB Output is correct
8 Correct 32 ms 9964 KB Output is correct
9 Incorrect 29 ms 2616 KB 1st lines differ - on the 1st token, expected: '99999', found: '0'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 2132 KB Output is correct
2 Correct 29 ms 2616 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 79 ms 7260 KB Output is correct
6 Correct 81 ms 7248 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 63 ms 5672 KB Output is correct
9 Correct 69 ms 6728 KB Output is correct
10 Correct 21 ms 2148 KB Output is correct
11 Correct 27 ms 2620 KB Output is correct
12 Correct 0 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 0 ms 212 KB Output is correct
18 Correct 28 ms 3296 KB Output is correct
19 Correct 36 ms 3764 KB Output is correct
20 Correct 27 ms 3064 KB Output is correct
21 Correct 32 ms 3536 KB Output is correct
22 Correct 28 ms 3164 KB Output is correct
23 Correct 32 ms 3404 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 9 ms 7636 KB Output is correct
26 Correct 21 ms 8148 KB Output is correct
27 Correct 17 ms 8532 KB Output is correct
28 Correct 35 ms 10044 KB Output is correct
29 Correct 28 ms 10048 KB Output is correct
30 Correct 32 ms 10048 KB Output is correct
31 Correct 32 ms 9964 KB Output is correct
32 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '0'
33 Halted 0 ms 0 KB -