답안 #626794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
626794 2022-08-11T19:23:30 Z welleyth 메기 농장 (IOI22_fish) C++17
37 / 100
1000 ms 358816 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;

constexpr int NN = 1e5 + 10;

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

int cnt[NN];
vector<int> YY[NN];
vector<int> val[NN];
vector<int> possibleLen[NN];

long long getSum(int x,int r){
    long long ans = 0;
    for(int i = 0; i < YY[x].size(); i++){
        if(YY[x][i] < r)
            ans += val[x][i];
    }
    return ans;
}

mt19937 rnd(time(nullptr));

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
    long long dp[2][4444][4444];
    for(int i = 0; i < 2; i++){
        for(int j = 0; j < 4444; j++){
            for(int t = 0; t < 4444; t++){
                dp[i][j][t] = 0;
            }
        }
    }
    set<int> st[N+22];
    for(int i = 0; i < M; i++){
//        g[X[i]+2][Y[i]] = W[i];
        YY[X[i]+2].push_back(Y[i]);
        val[X[i]+2].push_back(W[i]);
        for(int j = max(2,X[i]+1); j <= X[i]+3; j++){
            st[j].insert(Y[i]+1);
        }
    }

    for(int i = 0; i < N+2; i++){
        st[i].insert(0);
        possibleLen[i] = vector<int>(st[i].begin(),st[i].end());
    }

//    cerr << getSum(2,3) << "\n";
//    return 0;

    long long ans = 0;

    for(int i = 2; i < N+2; i++){
        int pr[2];
        for(pr[0] = 0; pr[0] < possibleLen[i-1].size(); pr[0]++){
            for(pr[1] = 0; pr[1] < possibleLen[i-2].size(); pr[1]++){
                for(int cur = 0; cur < possibleLen[i].size(); cur++){
                    int l0 = possibleLen[i-1][pr[0]];
                    int l1 = possibleLen[i-2][pr[1]];
                    int lcur = possibleLen[i][cur];
                    if(lcur <= l0){
                        dp[1][pr[0]][cur] = max(dp[1][pr[0]][cur],dp[0][pr[1]][pr[0]] + getSum(i+1,lcur) - getSum(i,lcur));
                    } else if(lcur <= l1){
                        dp[1][pr[0]][cur] = max(dp[1][pr[0]][cur],dp[0][pr[1]][pr[0]] + getSum(i+1,lcur) - getSum(i,l0));
                    } else {
                        dp[1][pr[0]][cur] = max(dp[1][pr[0]][cur],dp[0][pr[1]][pr[0]] + getSum(i+1,lcur) - getSum(i,l0)
                                            + max(0ll,getSum(i-1,lcur)-getSum(i-1,l0)) - max(0ll,getSum(i-1,l1)-getSum(i-1,l0)));
                    }
                    ans = max(ans,dp[1][pr[0]][cur]);
//                    cerr << i << " " << l1 << " " << l0 << " " << lcur << " " << dp[1][pr[0]][cur] << "\n";
//                    if(dp[0][pr[0]][cur] == 0)
//                        continue;
                }
            }
        }
        for(pr[0] = 0; pr[0] < possibleLen[i-1].size(); pr[0]++){
            for(pr[1] = 0; pr[1] < possibleLen[i-2].size(); pr[1]++){
                dp[0][pr[1]][pr[0]] = 0;
            }
        }
        for(pr[0] = 0; pr[0] < possibleLen[i-1].size(); pr[0]++){
            for(int cur = 0; cur < possibleLen[i].size(); cur++){
                dp[0][pr[0]][cur] = dp[1][pr[0]][cur];
                dp[1][pr[0]][cur] = 0;
            }
        }
    }
//    for(int i = 0; i < N+2; i++){
//        for(int j = 0; j < 10; j++){
//            for(int t = 0; t < 10; t++){
//                ans = max(ans,dp[i][j][t]);
//            }
//        }
//    }

    return ans;
}
/**
10000 2
0 0 1
0 1 1

5 4
0 2 5
1 1 2
4 4 1
3 3 3


**/

Compilation message

fish.cpp: In function 'long long int getSum(int, int)':
fish.cpp:18:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |     for(int i = 0; i < YY[x].size(); i++){
      |                    ~~^~~~~~~~~~~~~~
fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:58:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for(pr[0] = 0; pr[0] < possibleLen[i-1].size(); pr[0]++){
      |                        ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:59:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |             for(pr[1] = 0; pr[1] < possibleLen[i-2].size(); pr[1]++){
      |                            ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:60:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |                 for(int cur = 0; cur < possibleLen[i].size(); cur++){
      |                                  ~~~~^~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:79:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |         for(pr[0] = 0; pr[0] < possibleLen[i-1].size(); pr[0]++){
      |                        ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:80:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |             for(pr[1] = 0; pr[1] < possibleLen[i-2].size(); pr[1]++){
      |                            ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:84:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |         for(pr[0] = 0; pr[0] < possibleLen[i-1].size(); pr[0]++){
      |                        ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:85:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |             for(int cur = 0; cur < possibleLen[i].size(); cur++){
      |                              ~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1107 ms 338524 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 148 ms 316492 KB Output is correct
2 Execution timed out 1106 ms 346012 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 329016 KB Output is correct
2 Correct 160 ms 329008 KB Output is correct
3 Correct 209 ms 335088 KB Output is correct
4 Correct 204 ms 334220 KB Output is correct
5 Correct 265 ms 342292 KB Output is correct
6 Correct 250 ms 342352 KB Output is correct
7 Correct 278 ms 342332 KB Output is correct
8 Correct 374 ms 342380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 145 ms 316512 KB Output is correct
2 Correct 152 ms 316472 KB Output is correct
3 Correct 150 ms 316404 KB Output is correct
4 Correct 149 ms 316432 KB Output is correct
5 Correct 151 ms 316416 KB Output is correct
6 Correct 177 ms 316468 KB Output is correct
7 Correct 147 ms 316456 KB Output is correct
8 Correct 150 ms 316500 KB Output is correct
9 Correct 147 ms 316556 KB Output is correct
10 Correct 175 ms 316680 KB Output is correct
11 Correct 156 ms 316640 KB Output is correct
12 Correct 153 ms 316684 KB Output is correct
13 Correct 148 ms 316484 KB Output is correct
14 Correct 160 ms 316660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 145 ms 316512 KB Output is correct
2 Correct 152 ms 316472 KB Output is correct
3 Correct 150 ms 316404 KB Output is correct
4 Correct 149 ms 316432 KB Output is correct
5 Correct 151 ms 316416 KB Output is correct
6 Correct 177 ms 316468 KB Output is correct
7 Correct 147 ms 316456 KB Output is correct
8 Correct 150 ms 316500 KB Output is correct
9 Correct 147 ms 316556 KB Output is correct
10 Correct 175 ms 316680 KB Output is correct
11 Correct 156 ms 316640 KB Output is correct
12 Correct 153 ms 316684 KB Output is correct
13 Correct 148 ms 316484 KB Output is correct
14 Correct 160 ms 316660 KB Output is correct
15 Correct 152 ms 316524 KB Output is correct
16 Execution timed out 1092 ms 316692 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 145 ms 316512 KB Output is correct
2 Correct 152 ms 316472 KB Output is correct
3 Correct 150 ms 316404 KB Output is correct
4 Correct 149 ms 316432 KB Output is correct
5 Correct 151 ms 316416 KB Output is correct
6 Correct 177 ms 316468 KB Output is correct
7 Correct 147 ms 316456 KB Output is correct
8 Correct 150 ms 316500 KB Output is correct
9 Correct 147 ms 316556 KB Output is correct
10 Correct 175 ms 316680 KB Output is correct
11 Correct 156 ms 316640 KB Output is correct
12 Correct 153 ms 316684 KB Output is correct
13 Correct 148 ms 316484 KB Output is correct
14 Correct 160 ms 316660 KB Output is correct
15 Correct 152 ms 316524 KB Output is correct
16 Execution timed out 1092 ms 316692 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 167 ms 329016 KB Output is correct
2 Correct 160 ms 329008 KB Output is correct
3 Correct 209 ms 335088 KB Output is correct
4 Correct 204 ms 334220 KB Output is correct
5 Correct 265 ms 342292 KB Output is correct
6 Correct 250 ms 342352 KB Output is correct
7 Correct 278 ms 342332 KB Output is correct
8 Correct 374 ms 342380 KB Output is correct
9 Correct 423 ms 351752 KB Output is correct
10 Correct 263 ms 333224 KB Output is correct
11 Correct 426 ms 349536 KB Output is correct
12 Correct 157 ms 316432 KB Output is correct
13 Correct 159 ms 316516 KB Output is correct
14 Correct 151 ms 316456 KB Output is correct
15 Correct 159 ms 316432 KB Output is correct
16 Correct 158 ms 316468 KB Output is correct
17 Correct 145 ms 316404 KB Output is correct
18 Correct 160 ms 329012 KB Output is correct
19 Correct 167 ms 329036 KB Output is correct
20 Correct 172 ms 328932 KB Output is correct
21 Correct 161 ms 329032 KB Output is correct
22 Correct 458 ms 349896 KB Output is correct
23 Correct 622 ms 358108 KB Output is correct
24 Correct 658 ms 358816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1107 ms 338524 KB Time limit exceeded
2 Halted 0 ms 0 KB -