답안 #164434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
164434 2019-11-20T14:41:10 Z 6aren Tetris (COCI17_tetris) C++14
80 / 80
14 ms 504 KB
#include <bits/stdc++.h>
using namespace std;

#define all(s) s.begin(), s.end()
#define vi vector<int>
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second

bool check[15][15];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int cnt[10];
int n, m;
string s[15];

void bfs(int u, int v, char color) {
    int x = u, y = v, xx = u, yy = v;
    queue<ii> q;
    q.push({u, v});
    check[u][v] = 1;
    while (!q.empty()) {
        ii o = q.front();
        q.pop();
        for (int i = 0; i < 4; i++) {
            int uu = o.x + dx[i];
            int vv = o.y + dy[i];
            if (!check[uu][vv] && s[uu][vv] == color) {
                q.push({uu, vv});
                check[uu][vv] = 1;
                x = min(x, uu);
                y = min(y, vv);
                xx = max(xx, uu);
                yy = max(yy, vv);
            }
        }
    }
    if (x == xx || y == yy) cnt[2]++;
    else if (xx - x == 1 && yy - y == 1) cnt[1]++;
    else if (xx - x == 1 && yy - y) {
        if (s[xx][yy] == color && s[x][y] == color) cnt[4]++;
        else if (s[xx][y] == color && s[x][yy] == color) cnt[3]++;
        else cnt[5]++;
    } else {
        if (s[x][y] == color && s[xx][yy] == color) cnt[3]++;
        else if (s[x][yy] == color && s[xx][y] == color) cnt[4]++;
        else cnt[5]++;
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> s[i];
        s[i] = " " + s[i];
    } 
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (!check[i][j] && s[i][j] != '.') {
                bfs(i, j, s[i][j]);
            } 
        }
    }
    for (int i = 1; i <= 5; i++) {
        cout << cnt[i] << endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 14 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct