답안 #704228

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704228 2023-03-02T01:16:02 Z ancuber1031 Dijamant (COCI22_dijamant) C++14
70 / 70
280 ms 66340 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'

int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};

void paint(int x, int y, vector<vector<int> > &g) {
    g[x][y] = 1;
    for (int i = 0; i < 4; ++i) {
        if (!g[x+dx[i]][y+dy[i]]) paint(x+dx[i],y+dy[i],g);
    }
}

signed main() {
    int n, m; cin>>n>>m;
    vector<vector<int> > g(n+2,vector<int>(m+2,0)), pre(n+2,vector<int>(m+2,0));
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            char x; cin>>x;
            g[i][j] = (x == '#');
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            pre[i][j] = pre[i][j-1]+g[i][j];
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (g[i][j]) {
                int k = 0;
                while(g[i+k][j+k] && g[i+k][j-k] && 
                (pre[i+k][j+k-1]-pre[i+k][j-k] == 0 || !k)) {
                    k++; 
                }
                int tk = k;
                k -= 2;
                while(g[i+tk][j+k] && g[i+tk][j-k] && 
                (pre[i+tk][j+k-1]-pre[i+tk][j-k] == 0 || !k) && k >= 0) {
                    k--;
                    tk++;
                }
                k++, tk--;
                //cout<<i<<' '<<j<<' '<<k<<' '<<tk<<endl;
                if (!k && g[i+tk][j] && tk) ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 440 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 432 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 440 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 432 KB Output is correct
6 Correct 1 ms 440 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 436 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 432 KB Output is correct
14 Correct 236 ms 61492 KB Output is correct
15 Correct 259 ms 63096 KB Output is correct
16 Correct 265 ms 58188 KB Output is correct
17 Correct 228 ms 58108 KB Output is correct
18 Correct 280 ms 66340 KB Output is correct
19 Correct 216 ms 56020 KB Output is correct
20 Correct 252 ms 66188 KB Output is correct
21 Correct 216 ms 56132 KB Output is correct
22 Correct 247 ms 59728 KB Output is correct
23 Correct 231 ms 56660 KB Output is correct
24 Correct 251 ms 61004 KB Output is correct
25 Correct 214 ms 55816 KB Output is correct
26 Correct 234 ms 57964 KB Output is correct