Submission #37241

#TimeUsernameProblemLanguageResultExecution timeMemory
37241wasylTetris (COCI17_tetris)C++11
80 / 80
0 ms2188 KiB
#include <vector> #include <iostream> #include <algorithm> #define d(...) __VA_ARGS__ #define all(x) (x).begin(), (x).end() #define eb(...) emplace_back(__VA_ARGS__) using namespace std;using ll=long long; template<class t>using V = vector< t >; const int INF = 1e9 + 1; struct Cords { int x, y; Cords() : x( INF ), y( INF ) {} Cords( int x, int y ) : x( x ), y( y ) {} }; inline Cords operator+ ( const Cords& a, const Cords& b ) { return Cords( a.x + b.x, a.y + b.y ); } inline Cords operator- ( const Cords& a, const Cords& b ) { return Cords( a.x - b.x, a.y - b.y ); } inline bool operator< ( const Cords& a, const Cords& b ) { return a.x == b.x? a.y < b.y : a.x < b.x; } inline bool operator== ( const Cords& a, const Cords& b ) { return a.x == b.x and a.y == b.y; } inline bool operator== ( const V< Cords >& a, const V< Cords >& b ) { if ( a.size() != b.size() ) return false; for ( int i = 0; i < a.size(); ++i ) if ( !( a[i] == b[i] ) ) return false; return true; } inline V< V< char > > obroc ( const V< V< char > >& tab ) { V< V< char > > res ( tab[0].size(), V< char >( tab.size() ) ); for ( int i = 0; i < res.size(); ++i ) for ( int k = 0; k < res[i].size(); ++k ) res[i][k] = tab[k][i]; for ( int i = 0; i < res.size() / 2; ++i ) for ( int k = 0; k < res[i].size(); ++k ) swap( res[i][k], res[res.size() - 1 - i][k] ); return res; } int n, m, t; V< V< int > > odw; V< V< char > > plane; V< V< Cords > > figures { { { 0, 0 }, { 0, 1 }, { 1, 0 }, { 1, 1 } }, { { 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 } }, { { 0, 0 }, { 0, 1 }, { 1, -1 }, { 1, 0 } }, { { 0, 0 }, { 0, 1 }, { 1, 1 }, { 1, 2 } }, { { 0, 0 }, { 1, -1 }, { 1, 0 }, { 1, 1 } } }; V< Cords > curr; V< int > res ( 5, 0 ); V< Cords > sas { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } }; void dfs ( const Cords& a, const Cords& wz ) { odw[a.x][a.y] = t; curr.eb( a - wz ); for ( auto s : sas ) { auto na = a + s; if ( odw[na.x][na.y] < t and plane[a.x][a.y] == plane[na.x][na.y] ) dfs( na, wz ); } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; plane.resize( n + 2, V< char >( m + 2, '.' ) ); odw.resize( max( n + 2, m + 2 ), V< int >( max( n + 2, m + 2 ) ) ); for ( int i = 1; i <= n; ++i ) { string s; cin >> s; for ( int k = 1; k <= m; ++k ) plane[i][k] = s[k - 1]; } for ( int i = 0; i < 4; ++i ) { for ( int i = 1; i < plane.size() - 1; ++i ) for ( int k = 1; k < plane[i].size() - 1; ++k ) if ( plane[i][k] != '.' ) { ++t; dfs( Cords( i, k ), Cords( i, k ) ); sort( all( curr ) ); for ( int i = 0; i < figures.size(); ++i ) if ( figures[i] == curr ) ++res[i]; curr.clear(); } plane = obroc( plane ); } res[0] /= 4; res[1] /= 2; res[2] /= 2; res[3] /= 2; for ( int i = 0; i < res.size(); ++i ) cout << res[i] << '\n'; }

Compilation message (stderr)

tetris.cpp: In function 'bool operator==(V<Cords>&, V<Cords>&)':
tetris.cpp:42:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for ( int i = 0; i < a.size(); ++i )
                     ^
tetris.cpp: In function 'V<std::vector<char, std::allocator<char> > > obroc(V<std::vector<char, std::allocator<char> > >&)':
tetris.cpp:51:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for ( int i = 0; i < res.size(); ++i )
                     ^
tetris.cpp:52:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for ( int k = 0; k < res[i].size(); ++k )
                      ^
tetris.cpp:55:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for ( int i = 0; i < res.size() / 2; ++i )
                     ^
tetris.cpp:56:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for ( int k = 0; k < res[i].size(); ++k )
                      ^
tetris.cpp: In function 'int main()':
tetris.cpp:106:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for ( int i = 1; i < plane.size() - 1; ++i )
                      ^
tetris.cpp:107:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for ( int k = 1; k < plane[i].size() - 1; ++k )
                       ^
tetris.cpp:113:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      for ( int i = 0; i < figures.size(); ++i )
                         ^
tetris.cpp:122:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for ( int i = 0; i < res.size(); ++i )
                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...