# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
141375 |
2019-08-07T18:11:09 Z |
Vlatko |
Tetris (COCI17_tetris) |
C++14 |
|
2 ms |
376 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
int dr[4] = {-1, 0, 1, 0};
int dc[4] = {0, 1, 0, -1};
void dfs(vector<vector<char>> &grid, vector<pii> &tet, int r, int c, char ch) {
grid[r][c] = '.';
tet.emplace_back(r, c);
for (int d = 0; d < 4; ++d) {
int r1 = r + dr[d], c1 = c + dc[d];
if (r1 >= 0 && r1 < grid.size() && c1 >= 0 && c1 < grid[0].size()) {
if (grid[r1][c1] == ch) {
dfs(grid, tet, r1, c1, ch);
}
}
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
vector<vector<vector<pii>>> tets = {
{
{{0,0},{0,1},{1,0},{1,1}}
},
{
{{0,0},{0,1},{0,2},{0,3}},
{{0,0},{1,0},{2,0},{3,0}}
},
{
{{0,0},{0,1},{1,-1},{1,0}},
{{0,0},{1,0},{1,1},{2,1}}
},
{
{{0,0},{0,1},{1,1},{1,2}},
{{0,0},{1,-1},{1,0},{2,-1}}
},
{
{{0,0},{1,-1},{1,0},{1,1}},
{{0,0},{1,0},{1,1},{2,0}},
{{0,0},{0,1},{0,2},{1,1}},
{{0,0},{1,-1},{1,0},{2,0}}
}
};
int n, m;
cin >> n >> m;
vector<vector<char>> grid(n, vector<char>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> grid[i][j];
}
}
vector<int> ans(tets.size(), 0);
for (int r = 0; r < n; ++r) {
for (int c = 0; c < m; ++c) {
if (grid[r][c] != '.') {
vector<pii> tet;
dfs(grid, tet, r, c, grid[r][c]);
sort(tet.begin(), tet.end());
for (int i = 1; i < (int)tet.size(); ++i) {
tet[i].first -= tet[0].first;
tet[i].second -= tet[0].second;
}
tet[0].first = tet[0].second = 0;
for (int i = 0; i < (int)tets.size(); ++i) {
for (auto& rot : tets[i]) {
if (tet == rot) {
++ans[i];
i = 1e9;
break;
}
}
}
}
}
}
for (int cnt : ans) {
cout << cnt << endl;
}
}
Compilation message
tetris.cpp: In function 'void dfs(std::vector<std::vector<char> >&, std::vector<std::pair<int, int> >&, int, int, char)':
tetris.cpp:42:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (r1 >= 0 && r1 < grid.size() && c1 >= 0 && c1 < grid[0].size()) {
~~~^~~~~~~~~~~~~
tetris.cpp:42:58: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (r1 >= 0 && r1 < grid.size() && c1 >= 0 && c1 < grid[0].size()) {
~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |