Submission #118702

# Submission time Handle Problem Language Result Execution time Memory
118702 2019-06-19T12:33:16 Z sofhiasouza Maja (COCI18_maja) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

const int maxn = 110, maxs = 1e4+10;

int n, m, a, b, mat[maxn][maxn], k;

struct pt
{
	ll f;
	int sf, ss;

	bool operator > (const pt &k) const{
		if(f != k.f) return f > k.f;
		else if(sf != k.sf) return sf > k.sf;
		else return ss >= k.ss; 
	}

}dp[maxn][maxn][2];

pt solve()
{
	int mod = 0;
	for(int t = 1 ; t <= min(k, 1e4) ; t++)
	{	
		mod ^= 1;
		for(int i = 1 ; i <= n ; i++)
		{
			for(int j = 1 ; j <= m ; j++)
			{
				if(i == 3 and j == 3)
				{
					cout << dp[i-1][j][mod^1].f << ' ' << dp[i][j+1][mod^1].f << ' ' << dp[i][j-1][mod^1].f << ' ' << dp[i+1][j][mod^1].f << endl;
				}
				if(dp[i-1][j][mod^1] > dp[i+1][j][mod^1] and dp[i-1][j][mod^1] > dp[i][j-1][mod^1] and dp[i-1][j][mod^1] > dp[i][j+1][mod^1])
				{
					dp[i][j][mod] = dp[i-1][j][mod^1];
					if(mat[i][j] > dp[i-1][j][mod^1].sf)
					{
						dp[i][j][mod].ss = dp[i-1][j][mod^1].sf;
						dp[i][j][mod].sf = mat[i][j];
					}
					else if(mat[i][j] > dp[i-1][j][mod^1].ss) dp[i][j][mod].ss = mat[i][j];
				}
				else if(dp[i+1][j][mod^1] > dp[i-1][j][mod^1] and dp[i+1][j][mod^1] > dp[i][j-1][mod^1] and dp[i+1][j][mod^1] > dp[i][j+1][mod^1])
				{
					dp[i][j][mod] = dp[i+1][j][mod^1];
					if(mat[i][j] > dp[i+1][j][mod^1].sf)
					{
						dp[i][j][mod].ss = dp[i+1][j][mod^1].sf;
						dp[i][j][mod].sf = mat[i][j];
					}
					else if(mat[i][j] > dp[i+1][j][mod^1].ss) dp[i][j][mod].ss = mat[i][j];
				}
				else if(dp[i][j-1][mod^1] > dp[i-1][j][mod^1] and dp[i][j-1][mod^1] > dp[i+1][j][mod^1] and dp[i][j-1][mod^1] > dp[i][j+1][mod^1])
				{
					dp[i][j][mod] = dp[i][j-1][mod^1];
					if(mat[i][j] > dp[i][j-1][mod^1].sf)
					{
						dp[i][j][mod].ss = dp[i][j-1][mod^1].sf;
						dp[i][j][mod].sf = mat[i][j];
					}
					else if(mat[i][j] > dp[i][j-1][mod^1].ss) dp[i][j][mod].ss = mat[i][j];
				}
				else
				{
					dp[i][j][mod] = dp[i][j+1][mod^1];
					if(mat[i][j] > dp[i][j+1][mod^1].sf)
					{
						dp[i][j][mod].ss = dp[i][j+1][mod^1].sf;
						dp[i][j][mod].sf = mat[i][j];
					}
					else if(mat[i][j] > dp[i][j+1][mod^1].ss) dp[i][j][mod].ss = mat[i][j];
				}

				if(dp[i][j][mod].f != -1) dp[i][j][mod].f += mat[i][j];
				if(dp[i][j][mod].sf < dp[i][j][mod].ss) swap(dp[i][j][mod].sf, dp[i][j][mod].ss);
			}
		}
		cout << endl << t << endl; 
		for(int i = 1 ; i <= n ; i++)
		{
			for(int j = 1 ; j <= m ; j++)
			{
				cout << dp[i][j][mod].f << ' ';
			}
			cout << endl;
		}
		//cout << endl;
	}
	return dp[a][b][mod];
}

int main()
{
	cin >> n >> m >> a >> b >> k;

	for(int i = 1 ; i <= n ; i++)
	{
		for(int j = 1 ; j <= m ; j++)
		{
			cin >> mat[i][j];
		}
	}

	memset(dp, -1, sizeof dp);
	dp[a][b][0].f = 0;

	pt resp = solve();
	
	if(k < 1e4) cout << resp.f << endl;
	else cout << resp.f + (resp.sf+resp.ss)*k/2 << endl;
}

Compilation message

maja.cpp: In function 'pt solve()':
maja.cpp:25:33: error: no matching function for call to 'min(int&, double)'
  for(int t = 1 ; t <= min(k, 1e4) ; t++)
                                 ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from maja.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
maja.cpp:25:33: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'double')
  for(int t = 1 ; t <= min(k, 1e4) ; t++)
                                 ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from maja.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
maja.cpp:25:33: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'double')
  for(int t = 1 ; t <= min(k, 1e4) ; t++)
                                 ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from maja.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
maja.cpp:25:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  for(int t = 1 ; t <= min(k, 1e4) ; t++)
                                 ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from maja.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
maja.cpp:25:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  for(int t = 1 ; t <= min(k, 1e4) ; t++)
                                 ^