답안 #1067648

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1067648 2024-08-20T22:44:29 Z HorizonWest 메기 농장 (IOI22_fish) C++17
23 / 100
1000 ms 83120 KB
#include <bits/stdc++.h>
//#include "fish.h"
using namespace std;

#pragma GCC optimize("O3")
#define endl '\n'
#define db double
#define ll long long
#define pb push_back
#define fs first
#define sd second
#define Mod long(1e9 + 7)
#define all(x) x.begin(), x.end()
#define unvisited long(-1)
#define Eps double(1e-9)
#define _for(i, n) for(int i = 0; i < (n); i++)
#define dbg(x) cout << #x ": " << x << endl;

const int Max = 1e6 + 7, Inf = 1e9 + 7;

void print(bool x) { cout << (x ? "YES" : "NO") << endl; }

string tostring (__int128 x)
{
    string ans = "";
    while(x > 0)
    {
        ans += (x % 10 + '0');
        x /= 10;
    }
    reverse(all(ans));
    return ans;
}

long long max_weights(int n, int m, vector<int> X, vector<int> Y, vector<int> W) 
{
    vector <vector<pair<ll, ll>>> v(n + 7, vector <pair<ll, ll>> ());

    //vector <vector<ll>> v(n, vector <ll> (n+1, 0)); 
    unordered_map <int, unordered_map <int, int>> mp; 

    for(int i = 0; i < m; i++){
        //v[X[i]][Y[i]+1] = W[i];
        v[X[i]].push_back({ Y[i] + 1, W[i] });
        if(X[i] > 0) v[X[i]-1].push_back({ Y[i] + 1, 0 });
        if(X[i] > 1) v[X[i]-2].push_back({ Y[i] + 1, 0 });
        if(X[i] < n) v[X[i]+1].push_back({ Y[i] + 1, 0 });
        if(X[i] < n) v[X[i]+2].push_back({ Y[i] + 1, 0 });
    }

    for(int i = 0; i < n; i++)
    {
        v[i].push_back({ 0, 0 }); sort(all(v[i]));

        for(int j = 0; j < (int) v[i].size(); j++){
            if (j != 0) v[i][j].sd += v[i][j-1].sd;
            mp[i][v[i][j].fs] = j;
        }
    }

    auto C = [&] (int i, int j, int k) -> ll
    {
        ll ans = 0;
        if(i >= 0 && i < n) {
            ans = ans + max(0LL, v[i][mp[i][j]].sd - v[i][mp[i][k]].sd);
        }
        return ans;
    };

    vector <vector<ll>> dp1, dp2; ll ans = 0; 

    for(int i = 0; i < n; i++)
    {   
        dp1.push_back(vector <ll> (v[i].size(), 0));
        dp2.push_back(vector <ll> (v[i].size(), 0));

        for(int j = 0; j < (int) v[i].size(); j++)
        {
            int hj = v[i][j].fs;

            dp1[i][j] = C(i-1, hj, 0) + C(i+1, hj, 0);
            dp2[i][j] = C(i-1, hj, 0) + C(i+1, hj, 0);

            if(i > 1){
                for(int k = 0; k < (int) v[i-2].size(); k++){
                    int hk = v[i-2][k].fs; 
                    dp1[i][j] = max(dp1[i][j], (i > 1 ? dp2[i-2][k] : 0LL) + C(i-1, hj, hk) + C(i+1, hj, 0));
                }
            }

            if(i > 0){
                for(int k = 0; k < (int) v[i-1].size(); k++){    
                    int hk = v[i-1][k].fs; 
                    dp1[i][j] = max(dp1[i][j], (i != 0 ? dp1[i-1][k] : 0) + C(i-1, hj, hk) + C(i+1, hj, 0) - C(i, hk, 0));
                }
            
                for(int k = 0; k < (int) v[i-1].size(); k++){
                    int hk = v[i-1][k].fs; 
                    dp2[i][j] = max(dp2[i][j], (i != 0 ? dp1[i-1][k] : 0) - C(i, hj, 0) + C(i+1, hj, 0));
                    dp2[i][j] = max(dp2[i][j], (i != 0 ? dp2[i-1][k] : 0) - C(i, hj, 0) + C(i+1, hj, 0));
                }
            }

            ans = max(ans, max(dp1[i][j], dp2[i][j])); 
        }
    }

    return ans;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:98:25: warning: unused variable 'hk' [-Wunused-variable]
   98 |                     int hk = v[i-1][k].fs;
      |                         ^~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 45612 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Execution timed out 1083 ms 62440 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 40120 KB Output is correct
2 Correct 68 ms 40056 KB Output is correct
3 Correct 447 ms 49612 KB Output is correct
4 Correct 308 ms 49176 KB Output is correct
5 Correct 769 ms 64684 KB Output is correct
6 Correct 793 ms 63920 KB Output is correct
7 Correct 789 ms 64696 KB Output is correct
8 Correct 784 ms 64632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 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 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 12 ms 596 KB Output is correct
10 Correct 86 ms 1108 KB Output is correct
11 Correct 20 ms 600 KB Output is correct
12 Correct 27 ms 860 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 22 ms 832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 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 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 12 ms 596 KB Output is correct
10 Correct 86 ms 1108 KB Output is correct
11 Correct 20 ms 600 KB Output is correct
12 Correct 27 ms 860 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 22 ms 832 KB Output is correct
15 Correct 4 ms 600 KB Output is correct
16 Correct 470 ms 1268 KB Output is correct
17 Execution timed out 1049 ms 10296 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 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 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 12 ms 596 KB Output is correct
10 Correct 86 ms 1108 KB Output is correct
11 Correct 20 ms 600 KB Output is correct
12 Correct 27 ms 860 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 22 ms 832 KB Output is correct
15 Correct 4 ms 600 KB Output is correct
16 Correct 470 ms 1268 KB Output is correct
17 Execution timed out 1049 ms 10296 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 68 ms 40120 KB Output is correct
2 Correct 68 ms 40056 KB Output is correct
3 Correct 447 ms 49612 KB Output is correct
4 Correct 308 ms 49176 KB Output is correct
5 Correct 769 ms 64684 KB Output is correct
6 Correct 793 ms 63920 KB Output is correct
7 Correct 789 ms 64696 KB Output is correct
8 Correct 784 ms 64632 KB Output is correct
9 Correct 868 ms 83120 KB Output is correct
10 Execution timed out 1075 ms 44720 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1087 ms 45612 KB Time limit exceeded
2 Halted 0 ms 0 KB -