답안 #628189

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628189 2022-08-13T07:32:42 Z MarkBcc168 메기 농장 (IOI22_fish) C++17
9 / 100
127 ms 20208 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y, std::vector<int> w){
    vector<ll> col[n];
    for(int i=0; i<m; ++i){
        col[x[i]].push_back(i);
    }
    for(int i=0; i<n; ++i){
        sort(col[i].begin(), col[i].end(),
            [&](int p, int q){return y[p] < y[q];});
    }
    vector<ll> up(m,0), down(m,0);
    vector<ll> up_max(n,0), down_max(n,0);
    for(int i=0; i<n; ++i){
        if(col[i].size() == 0){
            if(i==0){
                up_max[i] = 0;
                down_max[i] = 0;
            }
            else{
                up_max[i] = up_max[i-1];
                down_max[i] = down_max[i-1];
            }
            continue;
        }
            
        //case 1: delete (i-1)-st column and start over
        ll mx = (i<2) ? 0LL : max(up_max[i-2], down_max[i-2]);
        for(int j=0; j<col[i].size(); ++j){
            if(j==0) up[col[i][0]] = mx + w[col[i][0]];
            else{
                up[col[i][j]] = up[col[i][j-1]] + w[col[i][j]];
            }
        }

        for(int j=col[i].size()-1; j>=0; --j){
            if(j==col[i].size()-1) down[col[i][j]] = mx + w[col[i][j]];
            else{
                down[col[i][j]] = down[col[i][j+1]] + w[col[i][j]];
            }
        }
        
        //case 2: actually using the previous column
        if(i>0 && col[i-1].size() > 0){
            int p, x = col[i-1].size();
            p = -1;

            for(int j=0; j<col[i].size(); j++){
                while(p < x-1 && y[col[i-1][p+1]] < y[col[i][j]]) p++;
                if(p==-1) continue;
                if(j==0) up[col[i][j]] = max(up[col[i][j]], up[col[i-1][p]] + w[col[i][j]]);
                else{
                    up[col[i][j]] = max({up[col[i][j]],
                        up[col[i-1][p]] + w[col[i][j]],
                        up[col[i][j-1]] + w[col[i][j]]});
                }
            }
            p = x;
            if(i>1){
                for(int j=x-1; j>=0; j--){
                    while(p > 0 && y[col[i-1][p-1]] > y[col[i][j]]) p--;
                    if(p==x) continue;
                    if(j==x-1) down[col[i][j]] = max(down[col[i][j]], down[col[i-1][p]] + w[col[i][j]]);
                    else{
                        down[col[i][j]] = max({down[col[i][j]],
                            down[col[i-1][p]] + w[col[i][j]],
                            down[col[i][j+1]] + w[col[i][j]]});
                    }
                }
            }
        }
        if(i==0){
            up_max[i] = up[col[i][col[i].size()-1]];
            down_max[i] = down[col[i][0]];
        }
        else{
            up_max[i] = max(up_max[i-1], up[col[i][col[i].size()-1]]);
            down_max[i] = max(down_max[i-1], down[col[i][0]]);
        }
    }
    /*for(int i=0; i<n; ++i){
        cout << up_max[i] << " " << down_max[i] << "\n";
    }*/
    return max(up_max[n-2], down_max[n-1]);
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:31:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         for(int j=0; j<col[i].size(); ++j){
      |                      ~^~~~~~~~~~~~~~
fish.cpp:39:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             if(j==col[i].size()-1) down[col[i][j]] = mx + w[col[i][j]];
      |                ~^~~~~~~~~~~~~~~~~
fish.cpp:50:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |             for(int j=0; j<col[i].size(); j++){
      |                          ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 7660 KB Output is correct
2 Correct 39 ms 9020 KB Output is correct
3 Correct 3 ms 4180 KB Output is correct
4 Correct 3 ms 4180 KB Output is correct
5 Correct 127 ms 18496 KB Output is correct
6 Correct 126 ms 20208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 67 ms 11568 KB Output is correct
3 Correct 80 ms 13792 KB Output is correct
4 Correct 33 ms 7616 KB Output is correct
5 Correct 40 ms 8920 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 3 ms 4180 KB Output is correct
11 Correct 3 ms 4180 KB Output is correct
12 Correct 32 ms 7744 KB Output is correct
13 Correct 39 ms 9052 KB Output is correct
14 Correct 33 ms 7672 KB Output is correct
15 Correct 37 ms 8644 KB Output is correct
16 Correct 33 ms 7880 KB Output is correct
17 Correct 36 ms 8636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Correct 3 ms 4180 KB Output is correct
3 Incorrect 24 ms 7500 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 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 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '165331649672'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 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 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '165331649672'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 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 Incorrect 1 ms 212 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '165331649672'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4180 KB Output is correct
2 Correct 3 ms 4180 KB Output is correct
3 Incorrect 24 ms 7500 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 7660 KB Output is correct
2 Correct 39 ms 9020 KB Output is correct
3 Correct 3 ms 4180 KB Output is correct
4 Correct 3 ms 4180 KB Output is correct
5 Correct 127 ms 18496 KB Output is correct
6 Correct 126 ms 20208 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 67 ms 11568 KB Output is correct
9 Correct 80 ms 13792 KB Output is correct
10 Correct 33 ms 7616 KB Output is correct
11 Correct 40 ms 8920 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 3 ms 4180 KB Output is correct
17 Correct 3 ms 4180 KB Output is correct
18 Correct 32 ms 7744 KB Output is correct
19 Correct 39 ms 9052 KB Output is correct
20 Correct 33 ms 7672 KB Output is correct
21 Correct 37 ms 8644 KB Output is correct
22 Correct 33 ms 7880 KB Output is correct
23 Correct 36 ms 8636 KB Output is correct
24 Correct 3 ms 4180 KB Output is correct
25 Correct 3 ms 4180 KB Output is correct
26 Incorrect 24 ms 7500 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '16359027219341'
27 Halted 0 ms 0 KB -