Submission #472745

#TimeUsernameProblemLanguageResultExecution timeMemory
472745MamdouhNTetris (COCI17_tetris)C++14
80 / 80
1 ms204 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define endl "\n" int n,m; char ar[11][11]; vector<pair<int,int>>points; map<int,int>repsx,repsy; int shapes[6]; void solve(int x,int y,char color) { if(ar[x][y]!=color)return; points.push_back({x,y}); ar[x][y] = '.'; if(x<n-1)solve(x+1,y,color); if(y>0)solve(x,y-1,color); if(y<m-1)solve(x,y+1,color); } void determine_shape() { repsx.clear(); repsy.clear(); int ret = -1; for(auto v:points) { repsx[v.first]++; repsy[v.second]++; //cout<<v.first<<" "<<v.second<<" "<<repsx[v.first]<<" "<<repsy[v.second]<<endl; if(repsx[v.first]==4||repsy[v.second]==4)ret =1; if(repsx[v.first]==3||repsy[v.second]==3)ret =4; } //cout<<ret<<endl; if(ret!=-1) { shapes[ret]++; return; } bool square = 1; int x=0,y=0; for(auto v:repsx) { if(v.second!=2)square=0; else x+=1; } for(auto v:repsy) { if(v.second!=2)square=0; else y+=1; } if(square)ret = 0; if(ret!=-1) { shapes[ret]++; return; } if(y==2) { int mini = 0; int maxi = 0; for(int i=0;i<points.size();i++) { if(points[i].first<points[mini].first)mini=i; if(points[i].first>points[maxi].first)maxi=i; } mini=points[mini].second; maxi=points[maxi].second; if(maxi<mini)ret = 3; else ret = 2; //cout<<"rety is "<<ret<<endl; shapes[ret]++; return; } if(x==2) { int mini = 0; int maxi = 0; for(int i=0;i<points.size();i++) { if(points[i].second<points[mini].second)mini=i; if(points[i].second>points[maxi].second)maxi=i; } mini=points[mini].first; maxi=points[maxi].first; if(maxi<mini)ret = 2; else ret = 3; //cout<<"retx is "<<ret<<endl; shapes[ret]++; return; } } void print_grid() { for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { cout<<ar[i][j]; } cout<<endl; } } main() { cin>>n>>m; for(int i=0;i<n;i++)for(int j=0;j<m;j++)cin>>ar[i][j]; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { //cout<<"hddi "<<i<<" "<<j<<endl; if(ar[i][j]=='.')continue; points.clear(); solve(i,j,ar[i][j]); //print_grid(); determine_shape(); //cout<<"Hola soi dora"<<endl; } } for(int i=0;i<5;i++)cout<<shapes[i]<<endl; }

Compilation message (stderr)

tetris.cpp: In function 'void determine_shape()':
tetris.cpp:64:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         for(int i=0;i<points.size();i++)
      |                     ~^~~~~~~~~~~~~~
tetris.cpp:81:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |         for(int i=0;i<points.size();i++)
      |                     ~^~~~~~~~~~~~~~
tetris.cpp: At global scope:
tetris.cpp:106:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  106 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...