Submission #588126

# Submission time Handle Problem Language Result Execution time Memory
588126 2022-07-02T17:52:23 Z jmyszka2007 Coins (LMIO19_monetos) C++17
24.8548 / 100
25 ms 1224 KB
#include <bits/stdc++.h>
using namespace std;
int tab[310][310];
int res[310][310];
int main() {
	int t, n, a, b;
	cin >> t >> n >> a >> b;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			cin >> tab[i][j];
		}
	}
	int ans = 0;
	for(int i = 1; i <= n / 2; i++) {
		for(int j = 1; j <= n; j++) {
			if(tab[i][j]) {
				ans++;
			}
		}
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= n; j++) {
			if(i <= n / 2) {
				res[i][j] = 0;
			}
			else {
				res[i][j] = 1;
			}
		}
	}
	int tmp = ans;
	int mn = ans;
	int y = n / 2;
	int x = n;
	for(int i = n / 2 + 1; i <= n; i++) {
		for(int j = 1; j <= n / 2; j++) {
			if(!tab[i][j] && tab[y][x]) {
				ans--;
				mn = min(mn, ans);
			}
			if(tab[i][j] && !tab[y][x]) {
				ans++;
			}
			if(x == n / 2 + 1) {
				x = n;
				y--;
			}
			else {
				x--;
			}
		}
	}
	if(tmp == mn) {
		for(int k = 1; k <= n; k++) {
			for(int l = 1; l <= n; l++) {
				cout << res[k][l] << ' ';
			}
			cout << '\n';
		}
		return 0;
	}
	y = n / 2;
	x = n;
	for(int i = n / 2 + 1; i <= n; i++) {
		for(int j = 1; j <= n / 2; j++) {
			swap(res[i][j], res[y][x]);
			if(!tab[i][j] && tab[y][x]) {
				tmp--;
				mn = min(mn, ans);
			}
			if(tab[i][j] && !tab[y][x]) {
				tmp++;
			}
			if(tmp == mn) {
				for(int k = 1; k <= n; k++) {
					for(int l = 1; l <= n; l++) {
						cout << res[k][l] << ' ';
					}
					cout << '\n';
				}
				return 0;
			}
			if(x == n / 2 + 1) {
				x = n;
				y--;
			}
			else {
				x--;
			}
		}
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB K = 22
2 Incorrect 1 ms 340 KB K = 622
3 Partially correct 25 ms 1172 KB K = 20132
4 Partially correct 18 ms 1104 KB K = 22919
5 Partially correct 22 ms 1168 KB K = 18409
6 Partially correct 20 ms 1220 KB K = 21766
7 Partially correct 19 ms 1160 KB K = 22149
8 Partially correct 19 ms 1184 KB K = 20044
9 Partially correct 21 ms 1224 KB K = 21027
10 Partially correct 22 ms 1168 KB K = 21524