Submission #1111348

#TimeUsernameProblemLanguageResultExecution timeMemory
1111348Yang8onDijamant (COCI22_dijamant)C++17
70 / 70
320 ms241224 KiB
#include <bits/stdc++.h>
#define Y8o "diamond"
#define maxn (int) 2002
#define ll long long
#define pii pair<int, int>
#define gb(i, j) ((i >> j) & 1)
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define fi(i, a, b) for(int i = a; i <= b; i ++)
#define fid(i, a, b) for(int i = a; i >= b; i --)

//#define f first
//#define s second

using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    if(fopen(Y8o".inp", "r"))
    {
        freopen(Y8o".inp", "r", stdin);
        freopen(Y8o".out", "w", stdout);
    }
}
void ctime() {
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

int n, m, sol;
char c[maxn][maxn];
bool bio[maxn][maxn];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int mn_sum, mx_sum, mn_dif, mx_dif, ok, cnt;

void dfs (int x, int y) {
    if (x == 0 || x == n + 1 || y == 0 || y == m + 1) {
        ok = 0;
        return;
    }
    if (bio[x][y] || c[x][y] == '#') return;
    bio[x][y] = 1;
    cnt++;

    mn_sum = min(mn_sum, x + y);
    mx_sum = max(mx_sum, x + y);
    mn_dif = min(mn_dif, x - y);
    mx_dif = max(mx_dif, x - y);

    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        dfs(nx, ny);
    }
}
void solve() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> c[i][j];
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (bio[i][j] || c[i][j] == '#') continue;

            mn_sum = mn_dif = 1e9;
            mx_sum = mx_dif = -1e9;
            ok = 1;
            cnt = 0;

            dfs(i, j);

            if (mx_sum - mn_sum == mx_dif - mn_dif && (mx_sum - mn_sum) % 2 == 0 && ok) {
                int d = (mx_sum - mn_sum) / 2 + 1;
                if (cnt == 2 * d * d - 2 * d + 1) sol++;
            }
        }
    }
    cout << sol;
}


int main() {
    iof();

    int nTest = 1;
//    cin >> nTest;

    while(nTest --) {
        solve();
    }

    ctime();
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'void iof()':
Main.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(Y8o".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |         freopen(Y8o".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...