답안 #648982

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648982 2022-10-08T21:43:29 Z teokakabadze 메기 농장 (IOI22_fish) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;

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

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

ll max_weights(ll N, ll M, vector<ll> X, vector<ll> Y, vector<ll> 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}];
            }
        }
        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)
            {
                for(k = 0; k < v[i - 1].size() - 1; k++)
                dp[{i, j}] = max(dp[{i, j}], dp[{i - 1, k}] + p[{i, v[i - 1][k + 1] - 1}]);
            }
            else
            {
                while(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]}]); continue; }
                        while(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++;
                }
                dp[{i, j}] = max(dp[{i, j}], dp[{i, j - 1}] + p[{i, v[i][j]}] - p[{i, v[i][j - 1]}]);
            }
        }
    } 
    for(i = 0; i < v[N - 1].size() - 1; i++)
    ans = max(ans, dp[{N - 1, i}]); 
    return ans; 
}

/*int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> N >> M;
	for(i = 0; i < M; i++)
	{
	   cin >> x >> y >> w;
	   X.pb(x), Y.pb(y), W.pb(w);
	}
	cout << max_weights(N, M, X, Y, W) << "\n";
}*/

Compilation message

fish.cpp: In function 'll max_weights(ll, ll, std::vector<long long int>, std::vector<long long int>, std::vector<long long 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:54: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]
   54 |         for(j = 0; j < v[i].size() - 1; j++)
      |                    ~~^~~~~~~~~~~~~~~~~
fish.cpp:59: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]
   59 |                 for(k = 0; k < v[i - 1].size() - 1; k++)
      |                            ~~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:83: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]
   83 |     for(i = 0; i < v[N - 1].size() - 1; i++)
      |                ~~^~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccTxj4hz.o: in function `main':
grader.cpp:(.text.startup+0x25e): undefined reference to `max_weights(int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status