답안 #379793

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
379793 2021-03-19T10:23:03 Z FatihSolak Tetris (COCI17_tetris) C++17
80 / 80
1 ms 512 KB
#include <bits/stdc++.h>
#define N 15
using namespace std;
int vis[N][N];
char arr[N][N];
int ans[5];
int n,m;
vector<pair<int,int>> dx = {{0,1},{0,-1},{1,0},{-1,0}};
vector<pair<int,int>> nums;
map<vector<string>,int> mp;
bool is_inside(int x,int y){
    return x > 0 && x<=n && y>0 && y<=m;
}
void dfs(int i,int j){
    vis[i][j] = 1;
    nums.push_back({i,j});
    for(auto u:dx){
        int x = i+u.first,y=j+u.second;
        if(is_inside(x,y) && !vis[x][y] && arr[i][j] == arr[x][y]){
            dfs(x,y);
        }
    }
}
vector<vector<string>> figure =
{ 
    {
        "##**",
        "##**",
        "****",
        "****"
    },
    {
        "####",
        "****",
        "****",
        "****"
    },
    {
        "*##*",
        "##**",
        "****",
        "****"
    },
    {
        "##**",
        "*##*",
        "****",
        "****"
    },
    {
        "*#**",
        "###*",
        "****",
        "****"
    },
};
void rotate(vector<string> &v){
    vector<pair<int,int>> coord;
    for(int i=0;i<v.size();i++){
        for(int j=0;j<v[i].size();j++){
            if(v[i][j] == '#')coord.push_back({-j,i});
        }
    }
    vector<string> tmp = {"****","****","****","****"};
    int minix = N,miniy = N;
    for(auto u:coord){
        minix = min(minix,u.first);
        miniy = min(miniy,u.second);
    }
    for(auto u:coord){
        tmp[u.first - minix][u.second - miniy] = '#';
    }
    //cout << endl;
    //for(auto u:tmp)cout << u <<endl;
    v = tmp;
}
int find(vector<string> a){
    for(int i = 0;i<figure.size();i++){
        //for(auto u:figure[i])cout << u << endl;
        for(int j = 0;j<4;j++){
            if(a == figure[i]){
                return i;
            }
            rotate(a);
        }
    }
    assert(0);
}
void solve(){
    cin >> n >> m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin >> arr[i][j];
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(!vis[i][j] && arr[i][j] != '.'){
                nums.clear();
                dfs(i,j);
                vector<string> tmp = {"****","****","****","****"};
                int minix = N,miniy = N;
                for(auto u:nums){
                    minix = min(minix,u.first);
                    miniy = min(miniy,u.second);
                    //cout << u.first << " " << u.second << endl;
                }
                for(auto u:nums){
                    tmp[u.first - minix][u.second - miniy] = '#';
                }
                //for(auto u:tmp)cout << u <<endl;
                ans[find(tmp)]++;
                //return;
            }
        }
    }
    for(int i=0;i<5;i++){
        cout << ans[i] << endl;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef Local
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    #ifdef Local
    cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}

Compilation message

tetris.cpp: In function 'void rotate(std::vector<std::__cxx11::basic_string<char> >&)':
tetris.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
tetris.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for(int j=0;j<v[i].size();j++){
      |                     ~^~~~~~~~~~~~
tetris.cpp: In function 'int find(std::vector<std::__cxx11::basic_string<char> >)':
tetris.cpp:78:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::__cxx11::basic_string<char> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for(int i = 0;i<figure.size();i++){
      |                   ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 512 KB Output is correct