답안 #1067694

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1067694 2024-08-21T01:05:03 Z mariaclara 메기 농장 (IOI22_fish) C++17
64 / 100
97 ms 35668 KB
#include "fish.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> trio;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define mk make_pair
#define fr first 
#define sc second
 
ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    vector<ll> ans_col(N);
    vector<vector<pii>> val(N);
    vector<vector<ll>> dp[2];
    dp[0].resize(N); // x-1 < x
    dp[1].resize(N); // x-1 > x
 
    for(int i = 0; i < M; i++) val[X[i]].pb({Y[i], W[i]});
    
    dp[0][0].resize(sz(val[0])+1, 0);
    dp[1][0].resize(sz(val[0])+1, 0);
 
    for(int x = 1; x < N; x++) {
        sort(all(val[x]));
        reverse(all(val[x]));
 
        dp[0][x].resize(sz(val[x])+1);
        dp[1][x].resize(sz(val[x])+1);
 
        // >
        for(int i = 0, j = 0; i < sz(val[x]); i++) {
            auto [y,w] = val[x][i];
            if(i != 0) dp[1][x][i+1] = dp[1][x][i] + w;
 
            while(j < sz(val[x-1]) and val[x-1][j].fr > y) j++;
            
            dp[1][x][i+1] = max(dp[1][x][i+1], dp[1][x-1][j] + w); // LEMBRAR DE dp[1][x][j] max= dp[1][x][j-1]
            //cout << "x = " << x << ", i = " << i << ", y = " << y << ", w = " << w << ", dp = " << dp[1][x][i+1] << "\n";
        }
 
        // <
        ll w = 0;
        for(int i = sz(val[x]) - 1, j = sz(val[x-1]) - 1, y; i >= -1; i--) {
            if(i >= 0) y = val[x][i].fr;
            else y = N;
  
            while(j >= 0 and val[x-1][j].fr < y) {
                w = max(w, dp[0][x-1][j+1]);
                w += val[x-1][j].sc;
                dp[0][x][i+1] = max(dp[0][x][i+1], w);
                j--;
            }
 
            dp[0][x][i+1] = max({dp[0][x][i+1], ans_col[x-1], w});
            //cout << "x = " << x << ", i = " << i << ", y = " << y << ", w = " << w << ", dp = " << dp[0][x][i+1] << "\n";
        }
 
        dp[1][x][0] = max(dp[1][x][0], dp[0][x][0]);
        for(int i = 1; i <= sz(val[x]); i++)
            dp[1][x][i] = max({dp[1][x][i], dp[1][x][i-1], dp[0][x][i]});
 
        ans_col[x] = dp[1][x][sz(val[x])];
    }
 
    return ans_col[N-1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 18252 KB Output is correct
2 Correct 32 ms 20944 KB Output is correct
3 Correct 12 ms 14428 KB Output is correct
4 Correct 12 ms 14392 KB Output is correct
5 Correct 97 ms 34996 KB Output is correct
6 Correct 97 ms 35668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 48 ms 23332 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '40479197388443'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14424 KB Output is correct
2 Correct 12 ms 14428 KB Output is correct
3 Correct 25 ms 16928 KB Output is correct
4 Correct 24 ms 16988 KB Output is correct
5 Correct 38 ms 21480 KB Output is correct
6 Correct 37 ms 20820 KB Output is correct
7 Correct 38 ms 21328 KB Output is correct
8 Correct 38 ms 21332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 496 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 496 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 15 ms 3300 KB Output is correct
18 Correct 16 ms 3648 KB Output is correct
19 Correct 12 ms 3676 KB Output is correct
20 Correct 12 ms 3676 KB Output is correct
21 Correct 13 ms 3596 KB Output is correct
22 Correct 24 ms 6740 KB Output is correct
23 Correct 3 ms 860 KB Output is correct
24 Correct 8 ms 2396 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 3 ms 964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 496 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 15 ms 3300 KB Output is correct
18 Correct 16 ms 3648 KB Output is correct
19 Correct 12 ms 3676 KB Output is correct
20 Correct 12 ms 3676 KB Output is correct
21 Correct 13 ms 3596 KB Output is correct
22 Correct 24 ms 6740 KB Output is correct
23 Correct 3 ms 860 KB Output is correct
24 Correct 8 ms 2396 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 3 ms 964 KB Output is correct
27 Correct 2 ms 860 KB Output is correct
28 Correct 55 ms 15808 KB Output is correct
29 Correct 82 ms 21480 KB Output is correct
30 Correct 77 ms 21216 KB Output is correct
31 Correct 83 ms 21332 KB Output is correct
32 Correct 72 ms 22096 KB Output is correct
33 Correct 82 ms 21220 KB Output is correct
34 Correct 80 ms 21328 KB Output is correct
35 Correct 30 ms 8532 KB Output is correct
36 Correct 78 ms 21728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 14424 KB Output is correct
2 Correct 12 ms 14428 KB Output is correct
3 Correct 25 ms 16928 KB Output is correct
4 Correct 24 ms 16988 KB Output is correct
5 Correct 38 ms 21480 KB Output is correct
6 Correct 37 ms 20820 KB Output is correct
7 Correct 38 ms 21328 KB Output is correct
8 Correct 38 ms 21332 KB Output is correct
9 Correct 38 ms 21332 KB Output is correct
10 Correct 34 ms 12880 KB Output is correct
11 Correct 66 ms 25688 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 14 ms 14428 KB Output is correct
19 Correct 12 ms 14428 KB Output is correct
20 Correct 12 ms 14428 KB Output is correct
21 Correct 13 ms 14424 KB Output is correct
22 Correct 44 ms 20916 KB Output is correct
23 Incorrect 73 ms 25812 KB 1st lines differ - on the 1st token, expected: '77772396150817', found: '77771938846818'
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 18252 KB Output is correct
2 Correct 32 ms 20944 KB Output is correct
3 Correct 12 ms 14428 KB Output is correct
4 Correct 12 ms 14392 KB Output is correct
5 Correct 97 ms 34996 KB Output is correct
6 Correct 97 ms 35668 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Incorrect 48 ms 23332 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '40479197388443'
9 Halted 0 ms 0 KB -