Submission #44280

# Submission time Handle Problem Language Result Execution time Memory
44280 2018-03-31T08:51:53 Z JustInCase Tetris (COCI17_tetris) C++17
80 / 80
2 ms 868 KB
#include <bits/stdc++.h>
using namespace std;

//------------------------------------------------

struct Figure {
	int type;
	vector< int > xChanges, yChanges;

	Figure();
	Figure(int type, const vector< int > &xChanges, const vector< int > &yChanges);
};

Figure::Figure() {
	
}

Figure::Figure(int type, const vector< int > &xChanges, const vector< int > &yChanges)
	: type(type), xChanges(xChanges), yChanges(yChanges) {
}

//------------------------------------------------

char a[15][15];
vector< Figure > figures;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	vector< int > xChanges(4), yChanges(4);

	xChanges[0] = 0;
	xChanges[1] = 0;
	xChanges[2] = 1;
	xChanges[3] = 1;
	yChanges[0] = 0;
	yChanges[1] = 1;
	yChanges[2] = 0;
	yChanges[3] = 1;
	figures.push_back(Figure(1, xChanges, yChanges));

	xChanges[2] = 0;
	xChanges[3] = 0;
	yChanges[2] = 2;
	yChanges[3] = 3;
	figures.push_back(Figure(2, xChanges, yChanges));

	xChanges[1] = 1;
	xChanges[2] = 2;
	xChanges[3] = 3;
	yChanges[1] = 0;
	yChanges[2] = 0;
	yChanges[3] = 0;
	figures.push_back(Figure(2, xChanges, yChanges));

	xChanges[1] = 0;
	xChanges[2] = 1;
	xChanges[3] = 1;
	yChanges[1] = 1;
	yChanges[2] = -1;
	yChanges[3] = 0;
	figures.push_back(Figure(3, xChanges, yChanges));

	xChanges[1] = 1;
	xChanges[2] = 1;
	xChanges[3] = 2;
	yChanges[1] = 0;
	yChanges[2] = 1;
	yChanges[3] = 1;
	figures.push_back(Figure(3, xChanges, yChanges));

	xChanges[1] = 0;
	xChanges[2] = 1;
	xChanges[3] = 1;
	yChanges[1] = 1;
	yChanges[2] = 1;
	yChanges[3] = 2;
	figures.push_back(Figure(4, xChanges, yChanges));

	xChanges[1] = 1;
	xChanges[2] = 1;
	xChanges[3] = 2;
	yChanges[1] = 0;
	yChanges[2] = -1;
	yChanges[3] = -1;
	figures.push_back(Figure(4, xChanges, yChanges));

	xChanges[1] = 1;
	xChanges[2] = 1;
	xChanges[3] = 1;
	yChanges[1] = -1;
	yChanges[2] = 0;
	yChanges[3] = 1;
	figures.push_back(Figure(5, xChanges, yChanges));

	xChanges[1] = 1;
	xChanges[2] = 1;
	xChanges[3] = 2;
	yChanges[1] = 0;
	yChanges[2] = 1;
	yChanges[3] = 0;
	figures.push_back(Figure(5, xChanges, yChanges));

	xChanges[1] = 0;
	xChanges[2] = 0;
	xChanges[3] = 1;
	yChanges[1] = 1;
	yChanges[2] = 2;
	yChanges[3] = 1;
	figures.push_back(Figure(5, xChanges, yChanges));
	
	xChanges[1] = 1;
	xChanges[2] = 1;
	xChanges[3] = 2;
	yChanges[1] = -1;
	yChanges[2] = 0;
	yChanges[3] = 0;
	figures.push_back(Figure(5, xChanges, yChanges));

	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	
	int cnt[] = {0, 0, 0, 0, 0, 0};
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < m; j++) {
			if(a[i][j] != '.') {
				for(Figure f : figures) {
					bool isOk = true;
					for(int p = 1; p < 4; p++) {
						if(i + f.xChanges[p] >= 0 && i + f.xChanges[p] < n) {
							if(j + f.yChanges[p] >= 0 && j + f.yChanges[p] < m) {
								if(a[i + f.xChanges[p]][j + f.yChanges[p]] != a[i][j]) {
									isOk = false;
								}
							}
							else {
								isOk = false;
							}
						}
						else {
							isOk = false;
						}
					}

					if(isOk) {
						for(int p = 0; p < 4; p++) {
							a[i + f.xChanges[p]][j + f.yChanges[p]] = '.';
						}
						cnt[f.type]++;
						break;
					}
				}
			}
		}
	}
	
	for(int i = 1; i <= 5; i++) {
		cout << cnt[i] << endl;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 608 KB Output is correct
8 Correct 2 ms 868 KB Output is correct
9 Correct 2 ms 868 KB Output is correct
10 Correct 2 ms 868 KB Output is correct