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

Compiler report

cc1plus: error: '::main' must return 'int'

Code

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


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

const long SIZE = 600;

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

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

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

long scan(long p, bool skip1){

    for (long i = n; i >= 1; i--) {
        if(skip1 && i == 1){
            break;
        }
        long h = i-skip1;

        long j2 = 1;
        long j1 = 1;

        long l = 1;

        long ms = d[i][1].l - d[i-1][(i % 2 == 0)].l; 
        long s = ms;

        long safety = 0;
        while (j1 < m)
        {

            safety++;
            p = min(s, p);

            if(j2 < j1+h - 1 && j2 < m){
                j2++;
                ms += count_l_colum(i, j2, (j2-j1 + 1));
                continue;
            }

            //else
            if((ms - s) < 0){
                l++;
                s += count_l_colum(i, (j1+l-1), l);
                continue;
            }

            //else
            if((ms - s) >= 0 && j1 < j2 && l > 1){
                s -= count_r_colum(i, j1, l);
                ms -= count_r_colum(i, j1, (j2-j1 + 1));
                j1++;
                l--;
                continue;
            }
            else if (j2 >= m){
                break;
            }
            else
            {
                s -= count_r_colum(i, j1, l);
                ms -= count_r_colum(i, j1, (j2-j1 + 1));
                j1++;

                j2++;
                s += count_l_colum(i, (j1+l-1), l);
                ms += count_l_colum(i, j2, (j2-j1 + 1));
                continue;
            }
        }
        p = min(s, p);


        
      

    }     
    return p;   
}


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



    cin >> n >> m >> k;

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

    for (long i = 1; i <= n; i++) {
        for (long 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 (long i = 1; i <= n; i++) {
    //     for (long j = 1; j <= m; j++) {
    //         cout << "(" << d[i][j].l << " ; " << d[i][j].r << ")  " ;
    //     }
    //     cout << "\n";
    // }

    long 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 (long i = 1; i <= n; i++) {
        for (long j = 1; j <= m; j++) {
            if(v[i][j] != 0){
                v2[n+1-i][j] = v[i][j];
            }
        }
    }


    for (long i = 1; i <= n; i++) {
        for (long 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 (long i = 1; i <= n; i++) {
    //     for (long 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;

}