# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
379793 | FatihSolak | Tetris (COCI17_tetris) | C++17 | 1 ms | 512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |