Submission #242383

# Submission time Handle Problem Language Result Execution time Memory
242383 2020-06-27T13:38:42 Z valerikk T-Covering (eJOI19_covering) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;

#define ll long long

#define x first
#define y second
#define pb push_back
#define mp make_pair

#define all(a) (a).begin(), (a).end()

const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const ll oo = 2e18;

int n, m;
int **a;
bool **f;
short **d;
int **c;

bool ok(int i, int j) {
    return i >= 0 && i < n && j >= 0 && j < m;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m;
    a = new ll*[n];
    f = new bool*[n];
    d = new int*[n];
    c = new int*[n];
    for (int i = 0; i < n; ++i) {
        a[i] = new ll[m];
        f[i] = new bool[m];
        d[i] = new int[m];
        c[i] = new int[m];
        for (int j = 0; j < m; ++j) cin >> a[i][j];
    }
    memset(d, 255, sizeof(d));
    int k;
    cin >> k;
    while (k--) {
        int r, c;
        cin >> r >> c;
        f[r][c] = 1;
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (!f[i][j]) continue;
            for (int z = 0; z < 4; ++z) {
                int x = i + dx[z], y = j + dy[z];
                if (ok(x, y) && f[x][y]) {
                    d[i][j] = z;
                    d[x][y] = z ^ 2;
                }
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (f[i][j]) {
                if (~d[i][j]) {
                    ll mx = -oo;
                    for (int z = 0; z < 4; ++z) {
                        bool OK = 1;
                        for (int zz = 0; zz < 4; ++zz) {
                            if (zz != z) OK &= ok(i + dx[zz], j + dy[zz]);
                        }
                        if (OK) {
                            ll q = a[i][j];
                            for (int zz = 0; zz < 4; ++zz) {
                                if (zz != z) q += a[i + dx[zz]][j + dy[zz]];
                            }
                            mx = max(mx, q);
                        }
                    }
                    ans += mx;
                } else {
                    bool OK = 1;
                    for (int z = 0; z < 4; ++z) {
                        if (d[i][j] != z) OK &= ok(i + dx[z], j + dy[z]);
                    }
                    if (!OK) {
                        cout << "No\n";
                        return 0;
                    }
                    ll q = 0;
                    for (int z = 0; z < 4; ++z) {
                        if (d[i][j] != z) {
                            q += a[i + dx[z]][j + dy[z]];
                            ++c[i + dx[z]][j + dy[z]];
                        }
                    }
                    ans += q;
                }
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (c[i][j] > 1) {
                cout << "No\n";
                return 0;
            }
        }
    }
    cout << ans;
    return 0;
}

Compilation message

covering.cpp: In function 'int main()':
covering.cpp:30:18: error: cannot convert 'long long int**' to 'int**' in assignment
     a = new ll*[n];
                  ^
covering.cpp:32:19: error: cannot convert 'int**' to 'short int**' in assignment
     d = new int*[n];
                   ^
covering.cpp:35:24: error: cannot convert 'long long int*' to 'int*' in assignment
         a[i] = new ll[m];
                        ^
covering.cpp:37:25: error: cannot convert 'int*' to 'short int*' in assignment
         d[i] = new int[m];
                         ^
covering.cpp:41:26: warning: argument to 'sizeof' in 'void* memset(void*, int, size_t)' call is the same expression as the destination; did you mean to dereference it? [-Wsizeof-pointer-memaccess]
     memset(d, 255, sizeof(d));
                          ^