답안 #472761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
472761 2021-09-14T09:49:56 Z _L__ Tetris (COCI17_tetris) C++17
80 / 80
1 ms 204 KB
// This code is written by _L__
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>;
#define endl '\n'
#define F_word ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
typedef long long ll;
typedef long double ld;
const ll mod = 1e9+7, N = 1e5+300, inf = 1e18;
const ld E = 1e-6;
#define ff first
#define ss second

int n, m;
char a[15][15]; bool vis[15][15];
bool valid(int i, int j){return (i >= 0 && i < n && j >= 0 && j < m);}
bool figure1(int i, int j){
    return (valid(i, j+1) && valid(i+1, j) && valid(i+1, j+1)
        && !vis[i][j+1] && !vis[i+1][j+1] && !vis[i+1][j]
        && a[i][j] == a[i][j+1] && a[i+1][j] == a[i][j] && a[i][j] == a[i+1][j+1] && a[i][j] != '.');
}
bool figure2(int i, int j){
    return (valid(i, j+1) && valid(i, j+2) && valid(i, j+3)
        && !vis[i][j+1] && !vis[i][j+2] && !vis[i][j+3]
        && a[i][j] == a[i][j+1] && a[i][j] == a[i][j+2] && a[i][j] == a[i][j+3] && a[i][j] != '.');
}
bool figure2_1(int i, int j){
    return (valid(i+1, j) && valid(i+2, j) && valid(i+3, j)
        && !vis[i+1][j] && !vis[i+2][j] && !vis[i+3][j]
        && a[i][j] == a[i+1][j] && a[i+2][j] == a[i][j] && a[i][j] == a[i+3][j] && a[i][j] != '.');
}
bool figure3(int i, int j){
    return (valid(i, j+1) && valid(i+1, j) && valid(i+1, j-1)
        && !vis[i][j+1] && !vis[i+1][j] && !vis[i+1][j-1]
        && a[i][j] == a[i][j+1] && a[i+1][j] == a[i][j] && a[i][j] == a[i+1][j-1] && a[i][j] != '.');
}
bool figure3_1(int i, int j){
    return (valid(i+1, j) && valid(i+1, j+1) && valid(i+2, j+1)
        && !vis[i+1][j] && !vis[i+1][j+1] && !vis[i+2][j+1]
        && a[i][j] == a[i+1][j] && a[i+2][j+1] == a[i][j] && a[i][j] == a[i+1][j+1] && a[i][j] != '.');
}
bool figure4(int i, int j){
    return (valid(i, j+1) && valid(i+1, j+2) && valid(i+1, j+1)
        && !vis[i][j+1] && !vis[i+1][j+1] && !vis[i+1][j+2]
        && a[i][j] == a[i][j+1] && a[i+1][j+1] == a[i][j] && a[i][j] == a[i+1][j+2] && a[i][j] != '.');
}
bool figure4_1(int i, int j){
    return (valid(i+1, j) && valid(i+1, j-1) && valid(i+2, j-1)
        && !vis[i+1][j] && !vis[i+1][j-1] && !vis[i+2][j-1]
        && a[i][j] == a[i+1][j] && a[i+2][j-1] == a[i][j] && a[i][j] == a[i+1][j-1] && a[i][j] != '.');
}
bool figure5(int i, int j){
    return (valid(i+1, j+1) && valid(i+1, j) && valid(i+1, j-1)
        && !vis[i+1][j-1] && !vis[i+1][j+1] && !vis[i+1][j]
        && a[i][j] == a[i+1][j-1] && a[i+1][j+1] == a[i][j] && a[i][j] == a[i+1][j] && a[i][j] != '.');
}
bool figure5_1(int i, int j){
    return (valid(i+1, j) && valid(i+1, j+1) && valid(i+2, j)
        && !vis[i+1][j] && !vis[i+2][j] && !vis[i+1][j+1]
        && a[i][j] == a[i+1][j] && a[i+2][j] == a[i][j] && a[i][j] == a[i+1][j+1] && a[i][j] != '.');
}
bool figure5_2(int i, int j){
    return (valid(i+1, j) && valid(i+1, j-1) && valid(i+2, j)
        && !vis[i+1][j] && !vis[i+1][j-1] && !vis[i+2][j]
        && a[i][j] == a[i+1][j] && a[i+2][j] == a[i][j] && a[i][j] == a[i+1][j-1] && a[i][j] != '.');
}
bool figure5_3(int i, int j){
    return (valid(i, j+1) && valid(i+1, j+1) && valid(i, j+2)
        && !vis[i][j+1] && !vis[i+1][j+1] && !vis[i][j+2]
        && a[i][j] == a[i][j+1] && a[i][j+2] == a[i][j] && a[i][j] == a[i+1][j+1] && a[i][j] != '.');
}
int main(void){
    F_word;
    cin >> n >> m;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < m; ++j)
            cin >> a[i][j];
    int ans[5] = {};
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            if(vis[i][j]) continue;
            if(figure1(i,j)){
                vis[i][j] = vis[i][j+1] = vis[i+1][j+1] = vis[i+1][j] = 1;
                ans[0]++;
            }
            else if(figure2(i,j)){
                vis[i][j] = vis[i][j+1] = vis[i][j+2] = vis[i][j+3] = 1;
                ans[1]++;
            }
            else if(figure3(i,j)){
                vis[i][j] = vis[i][j+1] = vis[i+1][j-1] = vis[i+1][j] = 1;
                ans[2]++;
            }
            else if(figure4(i,j)){
                vis[i][j] = vis[i][j+1] = vis[i+1][j+2] = vis[i+1][j+1] = 1;
                ans[3]++;
            }
            else if(figure5(i,j)){
                vis[i][j] = vis[i+1][j-1] = vis[i+1][j+1] = vis[i+1][j] = 1;
                ans[4]++;
            }
            else if(figure5_1(i,j)){
                vis[i][j] = vis[i+1][j] = vis[i+1][j+1] = vis[i+2][j] = 1;
                ans[4]++;
            }
            else if(figure5_2(i,j)){
                vis[i][j] = vis[i+1][j] = vis[i+1][j-1] = vis[i+2][j] = 1;
                ans[4]++;
            }
            else if(figure5_3(i,j)){
                vis[i][j] = vis[i][j+1] = vis[i+1][j+1] = vis[i][j+2] = 1;
                ans[4]++;
            }
            else if(figure4_1(i,j)){
                vis[i][j] = vis[i+1][j] = vis[i+1][j-1] = vis[i+2][j-1] = 1;
                ans[3]++;
            }
            else if(figure3_1(i,j)){
                vis[i][j] = vis[i+1][j] = vis[i+1][j+1] = vis[i+2][j+1] = 1;
                ans[2]++;
            }
            else if(figure2_1(i,j)){
                vis[i][j] = vis[i+1][j] = vis[i+2][j] = vis[i+3][j] = 1;
                ans[1]++;
            }
        }
    }
    for(int i = 0; i < 5; ++i) cout << ans[i] << endl; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct