Submission #138088

# Submission time Handle Problem Language Result Execution time Memory
138088 2019-07-29T10:09:37 Z Linca_Robert Tetris (COCI17_tetris) C++14
80 / 80
2 ms 504 KB
#include<bits/stdc++.h>
using namespace std;

int N, M, cnt[6], nr;
int f[20][20];
char a[20][20];

int x_mn, x_mx, y_mn, y_mx;

void fill( int x, int y ){
    f[x][y] = nr;
    x_mn = min( x_mn, x );
    x_mx = max( x_mx, x );
    y_mn = min( y_mn, y );
    y_mx = max( y_mx, y );
    if( f[x + 1][y] < 0 && a[x + 1][y] == a[x][y] ) fill( x + 1, y );
    if( f[x - 1][y] < 0 && a[x - 1][y] == a[x][y] ) fill( x - 1, y );
    if( f[x][y + 1] < 0 && a[x][y + 1] == a[x][y] ) fill( x, y + 1 );
    if( f[x][y - 1] < 0 && a[x][y - 1] == a[x][y] ) fill( x, y - 1 );
}

inline void solve( int i, int j ){
    nr++;
    x_mn = N + 1, x_mx = 0;
    y_mn = M + 1, y_mx = 0;
    fill( i, j );
    int L = x_mx - x_mn + 1;
    int C = y_mx - y_mn + 1;

    if( L == 2 && C == 2 ){
        cnt[1]++; return; }
    if( (L == 1 && C == 4) || (L == 4 && C == 1) ){
        cnt[2]++; return; }

    if( L == 2 && C == 3 ){
        if( f[x_mx][y_mn] == f[x_mn][y_mx] ){
            cnt[3]++; return; }
        if( f[x_mn][y_mn] == f[x_mx][y_mx] ){
            cnt[4]++; return; }
        cnt[5]++;
        return;
    }

    if( L == 3 && C == 2 ){
        if( f[x_mn][y_mn] == f[x_mx][y_mx] ){
            cnt[3]++; return; }
        if( f[x_mn][y_mx] == f[x_mx][y_mn] ){
            cnt[4]++; return; }
        cnt[5]++;
        return;
    }
}

int main(){
    cin >> N >> M;
    for( int i = 1; i <= N; i++ )
        for( int j = 1; j <= M; j++ )
            cin >> a[i][j];

    for( int i = 1; i <= N; i++ )
        for( int j = 1; j <= M; j++ )
            f[i][j] = --nr;

    nr = 0;
    for( int i = 1; i <= N; i++ ){
        for( int j = 1; j <= M; j++ ){
            if( a[i][j] != '.' && f[i][j] < 0 )
                solve( i, j );
        }
    }

    for( int i = 1; i <= 5; i++ )
        cout << cnt[i] << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 380 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 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct