CSES - Datatähti 2024 alku - Results
Submission details
Task:Uolevin kalansaalis
Sender:MikaelM
Submission time:2023-10-30 18:41:31 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:34:20: error: no matching function for call to 'min(ll&, int&)'
   34 |             p = min(p, v[i][j]);
      |                 ~~~^~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,
                 from /usr/include/c++/11/cmath:1935,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from input/code.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  230 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:230:5: note:   template argument deduction/substitution failed:
input/code.cpp:34:20: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   34 |             p = min(p, v[i][j]);
      |                 ~~~^~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/specfun.h:45,...

Code

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 501;
int v[N][N];
ll s[N][N][N];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
ll y = 0, p = 1e18;
for(int i = 1; i <= k; i++){
int a, b;
char c;
cin >> a >> b >> c;
bool h = (c == 'H');
v[a][b] = (h ? 1 : -10);
y += v[a][b];
}
// kärki alas
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
s[i][j][1] = v[i][j];
p = min(p, v[i][j]);
if(i % 2 == 0){
// etäisyys vasemmalta = j * 2
// etäisyys oikealta = (m-j) * 2 + 1
// etäisyys ylhäältä = i
// suurin kolmio = min()
int d = min(min(j * 2, (m-j) * 2 + 1), i);
for(int t = 2; t <= d; t++){
ll u = v[i][j];
u += s[i-1][j][t-1] + s[i-1][j+1][t-1] - s[i-2][j][t-2];
p = min(p, u);
s[i][j][t] = u;
}
}
else{
// etäisyys vasemmalta = (j-1) * 2 + 1
// etäisyys oikealta = (m-j+1) * 2
// etäisyys ylhäältä = i
// suurin kolmio = min()
int d = min(min((j-1) * 2 + 1, (m-j+1) * 2), i);
for(int t = 2; t <= d; t++){
ll u = v[i][j];
u += s[i-1][j][t-1] + s[i-1][j-1][t-1] - s[i-2][j][t-2];
p = min(p, u);
s[i][j][t] = u;
}
}
}
}
// kärki ylös
for(int i = n; i >= 1; i--){
for(int j = m; j >= 1; j--){
s[i][j][1] = v[i][j];
p = min(p, v[i][j]);
if(i % 2 == 0){
// etäisyys vasemmalta = j * 2
// etäisyys oikealta = (m-j) * 2 + 1
// etäisyys alhaalta = n-i+1
// suurin kolmio = min()
int d = min(min(j * 2, (m-j) * 2 + 1), n-i+1);
for(int t = 2; t <= d; t++){
ll u = v[i][j];
u += s[i+1][j][t-1] + s[i+1][j+1][t-1] - s[i+2][j][t-2];
p = min(p, u);
s[i][j][t] = u;
}
}
else{
// etäisyys vasemmalta = (j-1) * 2 + 1
// etäisyys oikealta = (m-j+1) * 2
// etäisyys alhaalta = n-i+1
// suurin kolmio = min()
int d = min(min((j-1) * 2 + 1, (m-j+1) * 2), n-i+1);
for(int t = 2; t <= d; t++){
ll u = v[i][j];
u += s[i+1][j][t-1] + s[i+1][j-1][t-1] - s[i+2][j][t-2];
p = min(p, u);
s[i][j][t] = u;
}
}
}
}
cout << y-p;
}