답안 #1106981

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106981 2024-10-31T10:51:54 Z I_am_Polish_Girl 메기 농장 (IOI22_fish) C++17
9 / 100
93 ms 21420 KB
#include "fish.h"

#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <cmath>
#include <random>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <bitset>
#include <cmath>
#include <string>

using namespace std;


int log_ = 23;
long long inf = 8000000007000000007ll;
int mod = 1000000007;

int p = 523;


#include <vector>

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) 
{
	int n = N;
	

	vector <vector <pair <int, int>>> vp(n);


	for (int i = 0; i < X.size(); i++)
	{
		vp[X[i]].push_back({ Y[i] , W[i] });
	}

	for (int i = 0; i < n; i++)
	{
		sort(vp[i].begin(), vp[i].end());
	}

	vector <vector <long long>> dp0(n);
	vector <vector <long long>> dp1(n);

	for (int i = 0; i < n; i++)
	{
		dp0[i].resize(vp[i].size());
		dp1[i].resize(vp[i].size());
	}

	long long ans = 0;
	long long mx_ = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < vp[i].size(); j++)
		{
			ans = max(ans , mx_ + vp[i][j].second);
		}

		if (i > 0)
		{

			if (i != n - 1)
			{
				int ind = 0;

				int sz = vp[i].size();

				long long mx = 0;

				for (int j = 0; j < sz; j++)
				{
					while ((ind < vp[i - 1].size()) and (vp[i - 1][ind].first < vp[i][j].first))
					{

						mx = max(mx, dp0[i - 1][ind]);
						ind++;
					}

					mx = max(mx, mx_);

					dp0[i][j] = mx + vp[i][j].second;
					mx = max(mx, dp0[i][j]);
				}
			}

			if (i != 0)
			{
				int ind = vp[i - 1].size();

				ind--;

				int sz = vp[i].size();

				long long mx = 0;

				for (int j = sz - 1; j >= 0; j--)
				{
					while ((ind >= 0) and (vp[i - 1][ind].first > vp[i][j].first))
					{
						mx = max(mx, dp1[i - 1][ind]);
						ind--;

					}

					mx = max(mx, mx_);

					dp1[i][j] = mx + vp[i][j].second;

					if (i < n - 1)
					{
						dp0[i][j] = max(dp0[i][j], dp1[i][j]);
					}

					if ((ind >= 0) and(i != n - 1))
					{
						if (vp[i - 1][ind].first == vp[i][j].first)
						{
							dp0[i][j] = max(dp1[i - 1][ind] + vp[i][j].second, dp0[i][j]);
						}
					}

					mx = max(mx, dp1[i][j]);

				}

			}

			if (vp[i].size() > 0)
			{
				long long mx = -vp[i][0].second - 100;;
				for (int j = 0; j < vp[i].size(); j++)
				{
					mx += vp[i][j].second;
					mx = max(mx, dp0[i][j]);

					dp0[i][j] = mx;
				}
			}
		}
		else
		{
			long long s = 0;
			for (int j = 0; j < vp[i].size(); j++)
			{
				s += vp[i][j].second;

				dp0[i][j] = s;
				dp1[i][j] = 0;
			}
		}


		for (int j = 0; j < vp[i].size(); j++)
		{
			ans = max(ans, dp0[i][j]);
			ans = max(ans, dp1[i][j]);
		}

		if (i - 1 >= 0)
		{
			for (int j = 0; j < vp[i - 1].size(); j++)
			{
				mx_ = max(mx_, dp0[i - 1][j]);
				mx_ = max(mx_, dp1[i - 1][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:40:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  for (int i = 0; i < X.size(); i++)
      |                  ~~^~~~~~~~~~
fish.cpp:64:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |   for (int j = 0; j < vp[i].size(); j++)
      |                   ~~^~~~~~~~~~~~~~
fish.cpp:82:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |      while ((ind < vp[i - 1].size()) and (vp[i - 1][ind].first < vp[i][j].first))
      |              ~~~~^~~~~~~~~~~~~~~~~~
fish.cpp:141:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  141 |     for (int j = 0; j < vp[i].size(); j++)
      |                     ~~^~~~~~~~~~~~~~
fish.cpp:153:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  153 |    for (int j = 0; j < vp[i].size(); j++)
      |                    ~~^~~~~~~~~~~~~~
fish.cpp:163:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  163 |   for (int j = 0; j < vp[i].size(); j++)
      |                   ~~^~~~~~~~~~~~~~
fish.cpp:171:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  171 |    for (int j = 0; j < vp[i - 1].size(); j++)
      |                    ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 10456 KB Output is correct
2 Correct 31 ms 12260 KB Output is correct
3 Correct 3 ms 7248 KB Output is correct
4 Correct 4 ms 7248 KB Output is correct
5 Incorrect 93 ms 21420 KB 1st lines differ - on the 1st token, expected: '149814460735479', found: '299626719225511'
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 51 ms 14300 KB 1st lines differ - on the 1st token, expected: '40604614618209', found: '80957761098360'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7248 KB Output is correct
2 Correct 3 ms 7248 KB Output is correct
3 Correct 25 ms 12880 KB Output is correct
4 Correct 20 ms 11600 KB Output is correct
5 Correct 52 ms 19016 KB Output is correct
6 Correct 38 ms 19204 KB Output is correct
7 Correct 46 ms 19032 KB Output is correct
8 Correct 44 ms 19024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '286624093795'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '286624093795'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 504 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Incorrect 1 ms 336 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '286624093795'
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7248 KB Output is correct
2 Correct 3 ms 7248 KB Output is correct
3 Correct 25 ms 12880 KB Output is correct
4 Correct 20 ms 11600 KB Output is correct
5 Correct 52 ms 19016 KB Output is correct
6 Correct 38 ms 19204 KB Output is correct
7 Correct 46 ms 19032 KB Output is correct
8 Correct 44 ms 19024 KB Output is correct
9 Correct 43 ms 19024 KB Output is correct
10 Incorrect 35 ms 10800 KB 1st lines differ - on the 1st token, expected: '36454348383152', found: '42799032467356'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 10456 KB Output is correct
2 Correct 31 ms 12260 KB Output is correct
3 Correct 3 ms 7248 KB Output is correct
4 Correct 4 ms 7248 KB Output is correct
5 Incorrect 93 ms 21420 KB 1st lines differ - on the 1st token, expected: '149814460735479', found: '299626719225511'
6 Halted 0 ms 0 KB -