# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
164434 | 6aren | Tetris (COCI17_tetris) | C++14 | 14 ms | 504 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>
using namespace std;
#define all(s) s.begin(), s.end()
#define vi vector<int>
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second
bool check[15][15];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
int cnt[10];
int n, m;
string s[15];
void bfs(int u, int v, char color) {
int x = u, y = v, xx = u, yy = v;
queue<ii> q;
q.push({u, v});
check[u][v] = 1;
while (!q.empty()) {
ii o = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
int uu = o.x + dx[i];
int vv = o.y + dy[i];
if (!check[uu][vv] && s[uu][vv] == color) {
q.push({uu, vv});
check[uu][vv] = 1;
x = min(x, uu);
y = min(y, vv);
xx = max(xx, uu);
yy = max(yy, vv);
}
}
}
if (x == xx || y == yy) cnt[2]++;
else if (xx - x == 1 && yy - y == 1) cnt[1]++;
else if (xx - x == 1 && yy - y) {
if (s[xx][yy] == color && s[x][y] == color) cnt[4]++;
else if (s[xx][y] == color && s[x][yy] == color) cnt[3]++;
else cnt[5]++;
} else {
if (s[x][y] == color && s[xx][yy] == color) cnt[3]++;
else if (s[x][yy] == color && s[xx][y] == color) cnt[4]++;
else cnt[5]++;
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> s[i];
s[i] = " " + s[i];
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (!check[i][j] && s[i][j] != '.') {
bfs(i, j, s[i][j]);
}
}
}
for (int i = 1; i <= 5; i++) {
cout << cnt[i] << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |