답안 #1111348

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1111348 2024-11-12T07:20:03 Z Yang8on Dijamant (COCI22_dijamant) C++17
70 / 70
320 ms 241224 KB
#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

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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3152 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2896 KB Output is correct
5 Correct 1 ms 2868 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 1 ms 2640 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 2 ms 2896 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3152 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2896 KB Output is correct
5 Correct 1 ms 2868 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2640 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 1 ms 2640 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 2 ms 2896 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 320 ms 241224 KB Output is correct
15 Correct 36 ms 9288 KB Output is correct
16 Correct 93 ms 11336 KB Output is correct
17 Correct 256 ms 166476 KB Output is correct
18 Correct 60 ms 12216 KB Output is correct
19 Correct 129 ms 53588 KB Output is correct
20 Correct 134 ms 46664 KB Output is correct
21 Correct 101 ms 29256 KB Output is correct
22 Correct 99 ms 19016 KB Output is correct
23 Correct 95 ms 17996 KB Output is correct
24 Correct 105 ms 19284 KB Output is correct
25 Correct 301 ms 211788 KB Output is correct
26 Correct 57 ms 11336 KB Output is correct