CSES - Datatähti 2024 alku - Results
Submission details
Task:Uolevin kalansaalis
Sender:Tipu
Submission time:2023-11-12 21:22:42 +0200
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'll scan(ll, bool)':
input/code.cpp:53:28: error: no matching function for call to 'min(int&, ll&)'
   53 |                     p = min(s, p);
      |                         ~~~^~~~~~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/ios:40,
                 from /usr/include/c++/11/istream:38,
                 from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from input/code.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:230:5: note: candidate: 'template<class _Tp> 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:53:28: note:   deduced co...

Code

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;


struct Hex {       
  public:            
    ll l = 0;   
    ll r = 0;
};

const ll SIZE = 555;

ll n, m, k;
ll v[SIZE][SIZE];
ll v2[SIZE][SIZE];
Hex d[SIZE][SIZE];

ll count_l_colum(ll i, ll j, ll l){
    bool add = (i % 2 == 0);
    return (d[i][j].l - d[i-l][j - ll(ceil((l-add)/2.0))].l);
} 

ll count_r_colum(ll i, ll j, ll l){
    bool add = (i % 2 == 0);
    return (d[i][j].r - d[i-l][j + ll((l+add)/2.0)].r);
} 

ll scan(ll p, bool skip1){

    for (ll i = n; i >= 1; i--) {
        if(skip1 && i == 1){
            break;
        }
        for (int h = i-skip1; h > 0; h--)
        {        
            int l = 1;
            int j2 = 1;
            int j1 = 1;
            int s = d[i][1].l - d[i-1][(i % 2 == 0)].l; 

            while (j2 <= m)
            {
                if(h+j1 > m + 1){
                    break;
                }
                while(l < h){
                    j2++;
                    l = j2-j1 + 1;
                    s += count_l_colum(i, j2, l);
                }           
                if(l == h && j2 <= m){
                    p = min(s, p);
                    // cout << "( " << (i-skip1) << ";" << j1 << ";" << l << ") s:"  << s << " p:" << p << endl; 

                    s -= count_r_colum(i, j1, l);
                    j1++;
                    l = j2-j1 + 1;                    

                }

            }
        }        

      

    }     
    return p;   
}


ll main() {
    freopen("input.txt", "r", stdin);



    cin >> n >> m >> k;

    ll a, b;
    char c;
    for (ll i = 0; i < k; i++) {
        cin >> a >> b >> c;
        if(c == 'H'){
            v[a][b] = 1;
        }else{
            v[a][b] = -10;
        }
    }
    ll os = 0;

    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= m; j++) {
            bool add = 0;
            if(i % 2 == 0){
                add = 1;
            }
            os += v[i][j];
            d[i][j].l = v[i][j] + d[i-1][j-1+add].l;
            d[i][j].r = v[i][j] + d[i-1][j+add].r;
        }
    }

    // for (ll i = 1; i <= n; i++) {
    //     for (ll j = 1; j <= m; j++) {
    //         cout << "(" << d[i][j].l << " ; " << d[i][j].r << ")  " ;
    //     }
    //     cout << "\n";
    // }

    ll p = 1e6;
    p = scan(p,false);

    // cout << p << endl;
    // cout << os << endl;
    // assert(p >= os);
    // cout << "\n\n";
    bool fix = (n%2 == 0);
    n += fix;
    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= m; j++) {
            if(v[i][j] != 0){
                v2[n+1-i][j] = v[i][j];
            }
        }
    }


    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; j <= m; j++) {
            bool add = 0;
            if(i % 2 == 0){
                add = 1;
            }
            d[i][j].l = v2[i][j] + d[i-1][j-1+add].l;
            d[i][j].r = v2[i][j] + d[i-1][j+add].r;
        }
    }
    
    // for (ll i = 1; i <= n; i++) {
    //     for (ll j = 1; j <= m; j++) {
    //         cout << "(" << d[i][j].l << " ; " << d[i][j].r << ")  " ;
    //     }
    //     cout << "\n";
    // }

    p = min(scan(p, fix), p);

    // assert((n <= 5 && m <= 5));
    cout << os - p;

}