답안 #166941

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
166941 2019-12-04T17:57:13 Z johutha Growing Vegetable is Fun 3 (JOI19_ho_t3) C++17
컴파일 오류
0 ms 0 KB
#include <vector>
#include <iostream>
#include <algorithm>

#define int int64_t

using namespace std;

struct prefsum
{
	int n;
	vector<int> vals;

	void init(vector<int> ip)
	{
		n = ip.size();
		vals.resize(n + 1);
		for (int i = 1; i <= n; i++)
		{
			vals[i] = vals[i - 1] + ip[i - 1];
		}
	}

	int operator()(int l, int r)
	{
		return vals[r] - vals[l];
	}
};

struct dpstruct
{
	prefsum veg_R;
	prefsum veg_Y;
	prefsum veg_G;

	vector<int> pos_R;
	vector<int> pos_Y;
	vector<int> pos_G;

	int R = 0, Y = 0, G = 0;

	vector<vector<vector<vector<int>>>> table;

	int dp(int r, int y, int g, int last)
	{
		if (r < 0 || y < 0 || g < 0) return 1e15;
		if (r + y + g == 0) return 0;
		if (table[r][y][g][last] != -1) return table[r][y][g][last];

		int cost = 1e15;

		if (last == 0 && r != 0)
		{
			cost = min(dp(r - 1, y, g, 1), dp(r - 1, y, g, 2)) + max(0LL, veg_Y(0, pos_R[r - 1]) - y) + max(0LL, veg_G(0, pos_R[r - 1]) - g);
		}
		else if (last == 1 && y != 0)
		{
			cost = min(dp(r, y - 1, g, 0), dp(r, y - 1, g, 2)) + max(0LL, veg_R(0, pos_Y[y - 1]) - r) + max(0LL, veg_G(0, pos_Y[y - 1]) - g);
		}
		else if (last == 2 && g != 0)
		{
			cost = min(dp(r, y, g - 1, 0), dp(r, y, g - 1, 1)) + max(0LL, veg_Y(0, pos_G[g - 1]) - y) + max(0LL, veg_R(0, pos_G[g - 1]) - r);
		}

		return table[r][y][g][last] = cost;
	}

	void init(int n, string s)
	{
		vector<int> rs(n), ys(n), gs(n);
		
		
		for (int i = 0; i < n; i++)
		{
			char c = s[i];
			if (c == 'R')
			{
				R++;
				rs[i]++;
				pos_R.push_back(i);
			}
			else if (c == 'Y')
			{
				Y++;
				ys[i]++;
				pos_Y.push_back(i);
			}
			else
			{
				G++;
				gs[i]++;
				pos_G.push_back(i);
			}
		}

		veg_R.init(rs);
		veg_Y.init(ys);
		veg_G.init(gs);

		table.resize(R + 1, vector<vector<vector<int>>>(Y + 1, vector<vector<int>>(G + 1, vector<int>(3, -1))));
	}
};

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	string s;
	cin >> s;
	dpstruct dps;
	dps.init(n, s);

	int mmin = 1e18;

	for (int i = 0; i < 3; i++) mmin = min(mmin, dps.dp(dps.R, dps.Y, dps.G, i));

	if (mmin >= 1e15) cout << "-1\n";
	else cout << mmin << "\n";
}

Compilation message

joi2019_ho_t3.cpp: In member function 'int64_t dpstruct::dp(int64_t, int64_t, int64_t, int64_t)':
joi2019_ho_t3.cpp:54:92: error: no matching function for call to 'max(long long int, int64_t)'
    cost = min(dp(r - 1, y, g, 1), dp(r - 1, y, g, 2)) + max(0LL, veg_Y(0, pos_R[r - 1]) - y) + max(0LL, veg_G(0, pos_R[r - 1]) - g);
                                                                                            ^
In file included from /usr/include/c++/7/vector:60:0,
                 from joi2019_ho_t3.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:54:92: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t {aka long int}')
    cost = min(dp(r - 1, y, g, 1), dp(r - 1, y, g, 2)) + max(0LL, veg_Y(0, pos_R[r - 1]) - y) + max(0LL, veg_G(0, pos_R[r - 1]) - g);
                                                                                            ^
In file included from /usr/include/c++/7/vector:60:0,
                 from joi2019_ho_t3.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:54:92: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t {aka long int}')
    cost = min(dp(r - 1, y, g, 1), dp(r - 1, y, g, 2)) + max(0LL, veg_Y(0, pos_R[r - 1]) - y) + max(0LL, veg_G(0, pos_R[r - 1]) - g);
                                                                                            ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from joi2019_ho_t3.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:54:92: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
    cost = min(dp(r - 1, y, g, 1), dp(r - 1, y, g, 2)) + max(0LL, veg_Y(0, pos_R[r - 1]) - y) + max(0LL, veg_G(0, pos_R[r - 1]) - g);
                                                                                            ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from joi2019_ho_t3.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:54:92: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
    cost = min(dp(r - 1, y, g, 1), dp(r - 1, y, g, 2)) + max(0LL, veg_Y(0, pos_R[r - 1]) - y) + max(0LL, veg_G(0, pos_R[r - 1]) - g);
                                                                                            ^
joi2019_ho_t3.cpp:54:131: error: no matching function for call to 'max(long long int, int64_t)'
    cost = min(dp(r - 1, y, g, 1), dp(r - 1, y, g, 2)) + max(0LL, veg_Y(0, pos_R[r - 1]) - y) + max(0LL, veg_G(0, pos_R[r - 1]) - g);
                                                                                                                                   ^
In file included from /usr/include/c++/7/vector:60:0,
                 from joi2019_ho_t3.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:54:131: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t {aka long int}')
    cost = min(dp(r - 1, y, g, 1), dp(r - 1, y, g, 2)) + max(0LL, veg_Y(0, pos_R[r - 1]) - y) + max(0LL, veg_G(0, pos_R[r - 1]) - g);
                                                                                                                                   ^
In file included from /usr/include/c++/7/vector:60:0,
                 from joi2019_ho_t3.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:54:131: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t {aka long int}')
    cost = min(dp(r - 1, y, g, 1), dp(r - 1, y, g, 2)) + max(0LL, veg_Y(0, pos_R[r - 1]) - y) + max(0LL, veg_G(0, pos_R[r - 1]) - g);
                                                                                                                                   ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from joi2019_ho_t3.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:54:131: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
    cost = min(dp(r - 1, y, g, 1), dp(r - 1, y, g, 2)) + max(0LL, veg_Y(0, pos_R[r - 1]) - y) + max(0LL, veg_G(0, pos_R[r - 1]) - g);
                                                                                                                                   ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from joi2019_ho_t3.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:54:131: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
    cost = min(dp(r - 1, y, g, 1), dp(r - 1, y, g, 2)) + max(0LL, veg_Y(0, pos_R[r - 1]) - y) + max(0LL, veg_G(0, pos_R[r - 1]) - g);
                                                                                                                                   ^
joi2019_ho_t3.cpp:58:92: error: no matching function for call to 'max(long long int, int64_t)'
    cost = min(dp(r, y - 1, g, 0), dp(r, y - 1, g, 2)) + max(0LL, veg_R(0, pos_Y[y - 1]) - r) + max(0LL, veg_G(0, pos_Y[y - 1]) - g);
                                                                                            ^
In file included from /usr/include/c++/7/vector:60:0,
                 from joi2019_ho_t3.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:58:92: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t {aka long int}')
    cost = min(dp(r, y - 1, g, 0), dp(r, y - 1, g, 2)) + max(0LL, veg_R(0, pos_Y[y - 1]) - r) + max(0LL, veg_G(0, pos_Y[y - 1]) - g);
                                                                                            ^
In file included from /usr/include/c++/7/vector:60:0,
                 from joi2019_ho_t3.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:58:92: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t {aka long int}')
    cost = min(dp(r, y - 1, g, 0), dp(r, y - 1, g, 2)) + max(0LL, veg_R(0, pos_Y[y - 1]) - r) + max(0LL, veg_G(0, pos_Y[y - 1]) - g);
                                                                                            ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from joi2019_ho_t3.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:58:92: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
    cost = min(dp(r, y - 1, g, 0), dp(r, y - 1, g, 2)) + max(0LL, veg_R(0, pos_Y[y - 1]) - r) + max(0LL, veg_G(0, pos_Y[y - 1]) - g);
                                                                                            ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from joi2019_ho_t3.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:58:92: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
    cost = min(dp(r, y - 1, g, 0), dp(r, y - 1, g, 2)) + max(0LL, veg_R(0, pos_Y[y - 1]) - r) + max(0LL, veg_G(0, pos_Y[y - 1]) - g);
                                                                                            ^
joi2019_ho_t3.cpp:58:131: error: no matching function for call to 'max(long long int, int64_t)'
    cost = min(dp(r, y - 1, g, 0), dp(r, y - 1, g, 2)) + max(0LL, veg_R(0, pos_Y[y - 1]) - r) + max(0LL, veg_G(0, pos_Y[y - 1]) - g);
                                                                                                                                   ^
In file included from /usr/include/c++/7/vector:60:0,
                 from joi2019_ho_t3.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:58:131: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t {aka long int}')
    cost = min(dp(r, y - 1, g, 0), dp(r, y - 1, g, 2)) + max(0LL, veg_R(0, pos_Y[y - 1]) - r) + max(0LL, veg_G(0, pos_Y[y - 1]) - g);
                                                                                                                                   ^
In file included from /usr/include/c++/7/vector:60:0,
                 from joi2019_ho_t3.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:58:131: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t {aka long int}')
    cost = min(dp(r, y - 1, g, 0), dp(r, y - 1, g, 2)) + max(0LL, veg_R(0, pos_Y[y - 1]) - r) + max(0LL, veg_G(0, pos_Y[y - 1]) - g);
                                                                                                                                   ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from joi2019_ho_t3.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:58:131: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
    cost = min(dp(r, y - 1, g, 0), dp(r, y - 1, g, 2)) + max(0LL, veg_R(0, pos_Y[y - 1]) - r) + max(0LL, veg_G(0, pos_Y[y - 1]) - g);
                                                                                                                                   ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from joi2019_ho_t3.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:58:131: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
    cost = min(dp(r, y - 1, g, 0), dp(r, y - 1, g, 2)) + max(0LL, veg_R(0, pos_Y[y - 1]) - r) + max(0LL, veg_G(0, pos_Y[y - 1]) - g);
                                                                                                                                   ^
joi2019_ho_t3.cpp:62:92: error: no matching function for call to 'max(long long int, int64_t)'
    cost = min(dp(r, y, g - 1, 0), dp(r, y, g - 1, 1)) + max(0LL, veg_Y(0, pos_G[g - 1]) - y) + max(0LL, veg_R(0, pos_G[g - 1]) - r);
                                                                                            ^
In file included from /usr/include/c++/7/vector:60:0,
                 from joi2019_ho_t3.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:62:92: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t {aka long int}')
    cost = min(dp(r, y, g - 1, 0), dp(r, y, g - 1, 1)) + max(0LL, veg_Y(0, pos_G[g - 1]) - y) + max(0LL, veg_R(0, pos_G[g - 1]) - r);
                                                                                            ^
In file included from /usr/include/c++/7/vector:60:0,
                 from joi2019_ho_t3.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:62:92: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t {aka long int}')
    cost = min(dp(r, y, g - 1, 0), dp(r, y, g - 1, 1)) + max(0LL, veg_Y(0, pos_G[g - 1]) - y) + max(0LL, veg_R(0, pos_G[g - 1]) - r);
                                                                                            ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from joi2019_ho_t3.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:3462:5: note: candidate: template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)
     max(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:62:92: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
    cost = min(dp(r, y, g - 1, 0), dp(r, y, g - 1, 1)) + max(0LL, veg_Y(0, pos_G[g - 1]) - y) + max(0LL, veg_R(0, pos_G[g - 1]) - r);
                                                                                            ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from joi2019_ho_t3.cpp:3:
/usr/include/c++/7/bits/stl_algo.h:3468:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)
     max(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3468:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:62:92: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
    cost = min(dp(r, y, g - 1, 0), dp(r, y, g - 1, 1)) + max(0LL, veg_Y(0, pos_G[g - 1]) - y) + max(0LL, veg_R(0, pos_G[g - 1]) - r);
                                                                                            ^
joi2019_ho_t3.cpp:62:131: error: no matching function for call to 'max(long long int, int64_t)'
    cost = min(dp(r, y, g - 1, 0), dp(r, y, g - 1, 1)) + max(0LL, veg_Y(0, pos_G[g - 1]) - y) + max(0LL, veg_R(0, pos_G[g - 1]) - r);
                                                                                                                                   ^
In file included from /usr/include/c++/7/vector:60:0,
                 from joi2019_ho_t3.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:62:131: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t {aka long int}')
    cost = min(dp(r, y, g - 1, 0), dp(r, y, g - 1, 1)) + max(0LL, veg_Y(0, pos_G[g - 1]) - y) + max(0LL, veg_R(0, pos_G[g - 1]) - r);
                                                                                                                                   ^
In file included from /usr/include/c++/7/vector:60:0,
                 from joi2019_ho_t3.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
joi2019_ho_t3.cpp:62:131: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int64_t {aka long int}')
    cost = min(dp(r, y, g - 1, 0), dp(r, y, g - 1, 1)) + max(0LL, veg_Y(0, pos_G[g - 1]) - y) + max(0LL, veg_R(0, pos_G[g - 1]) - r);