답안 #648999

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648999 2022-10-08T22:31:07 Z teokakabadze 메기 농장 (IOI22_fish) C++17
0 / 100
1000 ms 122048 KB
#include<bits/stdc++.h>
using namespace std;

#define f first
#define s second
#define pb push_back
typedef long long ll;

ll i, j, k, t, l, x, y, w, ans;
vector<ll> v[100005];
map<pair<ll, ll>, ll> m, p, dp;
set<ll> s;
set<ll> :: iterator it, it1;

ll max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) 
{
    for(i = 0; i < M; i++)
    {
        v[X[i] + 1].pb(Y[i]);
        m[{X[i], Y[i]}] = W[i];
    }
    for(i = 0; i < N; i++)
    {
        v[i].pb(0), v[i].pb(N);
        sort(v[i].begin(), v[i].end());
    } 
    for(i = 0; i < N; i++)
    {
        if(i)
        for(j = 1; j < v[i - 1].size(); j++)
        if(v[i - 1][j]) s.insert(v[i - 1][j] - 1);
        for(j = 0; j < v[i].size() - 1; j++)
        s.insert(v[i][j]);
        if(i != N - 1)
        for(j = 0; j < v[i + 1].size() - 1; j++)
        s.insert(v[i + 1][j]);
        s.insert(N - 1);
        for(it = s.begin(); it != s.end(); it++)
        {
            p[{i, *it}] = 0;
            if(m[{i,*it}]) p[{i, *it}] = m[{i, *it}];
            if(it != s.begin())
            {
                it1 = it;
                it1--;
                p[{i, *it}] += p[{i, *it1}];
            }
            //cout << p[{i, *it}] << ' ';
        }
        //cout << endl;
        s.clear();
    } 
    for(i = 1; i < N; i++)
    {
        k = 0; t = 0;
        for(j = 0; j < v[i].size() - 1; j++)
        {
            if(j && v[i][j] == v[i][j - 1]) continue;
            if(!j)
            {
               // cout << v[i - 1].size() << endl;
                if(i == 1) dp[{i, j}] = dp[{i - 1, 0}] + p[{i - 1, 0}];
                for(l = 0; l < v[i - 1].size() - 1; l++)
                dp[{i, j}] = max(dp[{i, j}], dp[{i - 1, l}] + p[{i, v[i - 1][l + 1] - 1}]);
            }
            else
            {
                while(k < v[i - 1].size() && v[i - 1][k] < v[i][j])
                {
                    if(!v[i - 1][k])
                    {
                        if(i == 1) { dp[{i, j}] = max(dp[{i, j}], p[{0, v[i][j]}]); k++; continue; }
                        while(t < v[i - 2].size() && v[i - 2][t] < v[i][j])
                        {
                            dp[{i, j}] = max(dp[{i, j}], dp[{i - 2, t}] + p[{i - 1, v[i][j]}]);
                            t++;
                        }
                    }
                    else
                    dp[{i, j}] = max(dp[{i, j}], dp[{i - 1, k}] + p[{i - 1, v[i][j]}] - p[{i - 1, v[i - 1][k]}]);
                    k++;
                }
                if(j - 1) dp[{i, j}] = max(dp[{i, j}], dp[{i, j - 1}] + p[{i - 1, v[i][j]}] - p[{i - 1, v[i][j - 1]}]);
                //cout << p[{i - 1, v[i][j]}] << endl;
            }
            //cout << i << ' ' << j << ' ' << dp[{i, j}] << endl;
        }
    } 
    for(i = 0; i < v[N - 1].size() - 1; i++)
    ans = max(ans, dp[{N - 1, i}]); 
    return ans; 
}

Compilation message

fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:30:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |         for(j = 1; j < v[i - 1].size(); j++)
      |                    ~~^~~~~~~~~~~~~~~~~
fish.cpp:32:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         for(j = 0; j < v[i].size() - 1; j++)
      |                    ~~^~~~~~~~~~~~~~~~~
fish.cpp:35:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(j = 0; j < v[i + 1].size() - 1; j++)
      |                    ~~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:56:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         for(j = 0; j < v[i].size() - 1; j++)
      |                    ~~^~~~~~~~~~~~~~~~~
fish.cpp:63:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |                 for(l = 0; l < v[i - 1].size() - 1; l++)
      |                            ~~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:68:25: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |                 while(k < v[i - 1].size() && v[i - 1][k] < v[i][j])
      |                       ~~^~~~~~~~~~~~~~~~~
fish.cpp:73:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |                         while(t < v[i - 2].size() && v[i - 2][t] < v[i][j])
      |                               ~~^~~~~~~~~~~~~~~~~
fish.cpp:89:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     for(i = 0; i < v[N - 1].size() - 1; i++)
      |                ~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 605 ms 71580 KB Output is correct
2 Correct 726 ms 85936 KB Output is correct
3 Correct 211 ms 36984 KB Output is correct
4 Correct 188 ms 37072 KB Output is correct
5 Execution timed out 1039 ms 122048 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 196 ms 36980 KB Output is correct
2 Correct 189 ms 37024 KB Output is correct
3 Incorrect 224 ms 43600 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '2457537374003'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 196 ms 36980 KB Output is correct
2 Correct 189 ms 37024 KB Output is correct
3 Incorrect 224 ms 43600 KB 1st lines differ - on the 1st token, expected: '21261825233649', found: '2457537374003'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 605 ms 71580 KB Output is correct
2 Correct 726 ms 85936 KB Output is correct
3 Correct 211 ms 36984 KB Output is correct
4 Correct 188 ms 37072 KB Output is correct
5 Execution timed out 1039 ms 122048 KB Time limit exceeded
6 Halted 0 ms 0 KB -