답안 #269788

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
269788 2020-08-17T10:19:46 Z aZvezda Red-blue table (IZhO19_stones) C++14
0 / 100
37 ms 1528 KB
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
typedef unsigned long long ull;
template<class T, class T2> bool chkmax(T &a, const T2 &b) {return (a < b) ? a = b, 1 : 0;}
const int MAX_N = 1e1 + 10;
int tab[MAX_N][MAX_N];
 
int get(int n, int m) {
	int total = n * m;
	int ret = 0, retmask;
	for(int mask = 0; mask < (1 << total); mask ++) {
		for(int j = 0; j < total; j ++) {
			tab[j / m][j % m] = (bool)(mask & (1 << j)); 
		}
		int a = 0;
		for(int i = 0; i < n; i ++) {
			int curr = 0;
			for(int j = 0; j < m; j ++) {
				if(tab[i][j]) {
					curr ++;
				} else {
					curr --;
				}
			}
			if(curr > 0) {
				a ++;
			}
		}
		for(int j = 0; j < m; j ++) {
			int curr = 0;
			for(int i = 0; i < n; i ++) {
				if(tab[i][j]) {
					curr --;
				} else {
					curr ++;
				}
			}
			if(curr > 0) {
				a ++;
			}
		}
		if(chkmax(ret, a)) {
			retmask = mask;
		}
	}
	for(int j = 0; j < total; j ++) {
		tab[j / m][j % m] = (bool)(retmask & (1 << j)); 
	}
	cout << n << " " << m << " " << ret << endl;
	for(int i = 0; i < n; i ++) {
		for(int j = 0; j < m; j ++) {
			cout << tab[i][j] << " ";
		}
		cout << endl;
	}
	cout << "!" << endl;
	return ret;
}
 
int cnt[MAX_N];
char ans[MAX_N][MAX_N];
int getFast(int n, int m) {
	for(int i = 0; i < m; i ++) {
		cnt[i] = n;
	}
	bool rev = 0;
	if(n > m) {
		rev = true;
		swap(n, m);
	}
	int ret = max(n, m);
	int halfCnt = (m / 2) + 1;
	int gotten = 0, opti = 0;
	for(int i = 0; i < n; i ++) {
		//sort(cnt, cnt + m);
		//reverse(cnt, cnt + m);
		for(int j = 0; j < halfCnt; j ++) {
			cnt[j] --;
		}
		gotten ++;
		int curr = gotten;
		for(int j = 0; j < m; j ++) {
			if(cnt[j] * 2 > n) {
				curr ++;
			}
		}
		if(chkmax(ret, curr)) {
			opti = i + 1;
		}
	}
	for(int i = 0; i < n; i ++) {
		for(int j = 0; j < m; j ++) {
			ans[i][j] = '-';
		}
	}
	for(int i = 0; i < opti; i ++) {
		for(int j = 0; j < halfCnt; j ++) {
			ans[i][j] = '+';
		}
	}
	if(rev) {
		for(int i = 0; i < n; i ++) {
			for(int j = 0; j < m; j ++) {
				if(ans[i][j] == '-') {
					ans[i][j] = '+';
				} else {
					ans[i][j] = '-';
				}
			}
		}
	}
	if(rev) {
		for(int i = 0; i < n; i ++) {
			for(int j = 0; j < m; j ++) {
				if(i < j) {
					swap(ans[i][j], ans[j][i]);
				}
			}
		}
		swap(n, m);
	}
	int a = 0;
	for(int i = 0; i < n; i ++) {
		int curr = 0;
		for(int j = 0; j < m; j ++) {
			if(ans[i][j] == '+') {
				curr ++;
			} else {
				curr --;
			}
		}
		if(curr > 0) {
			a ++;
		}
	}
	for(int j = 0; j < m; j ++) {
		int curr = 0;
		for(int i = 0; i < n; i ++) {
			if(ans[i][j] == '+') {
				curr --;
			} else {
				curr ++;
			}
		}
		if(curr > 0) {
			a ++;
		}
	}
	//cout << a << " " << ret << endl; 
	if(a != ret) {
		cout << n << endl;
	} else {
		cout << ret << endl;
	}
	for(int i = 0; i < n; i ++) {
		for(int j = 0; j < m; j ++) {
			cout << ans[i][j];
		}
		cout << endl;
	}
	//assert(a == ret);
	return ret;
}
 
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int t; 
	cin >> t;
	while(t --) {
		int n, m;
		cin >> n >> m;
		getFast(n, m);
	}
}

Compilation message

stones.cpp: In function 'int get(int, int)':
stones.cpp:49:23: warning: 'retmask' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |   tab[j / m][j % m] = (bool)(retmask & (1 << j));
      |                       ^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB in the table A+B is not equal to 4
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB in the table A+B is not equal to 3
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB in the table A+B is not equal to 4
# 결과 실행 시간 메모리 Grader output
1 Incorrect 37 ms 1400 KB invalid character
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 35 ms 1528 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB in the table A+B is not equal to 4