답안 #269848

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
269848 2020-08-17T10:48:21 Z aZvezda Red-blue table (IZhO19_stones) C++14
15 / 100
336 ms 2680 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 = 1e3 + 10;
char 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) {
	bool rev = 0;
	if(n > m) {
		rev = true;
		swap(n, m);
	}
	for(int i = 0; i < m; i ++) {
		cnt[i] = n;
	}
	int ret = max(n, m);
	int halfCnt = (m / 2) + 1;
	int gotten = 0, opti = 0;
	for(int i = 0; i < n; i ++) {
		for(int j = 0; j < m; j ++) {
			ans[i][j] = '-';
		}
	}
	for(int i = 0; i < n; i ++) {
		//sort(cnt, cnt + m);
		//reverse(cnt, cnt + m);
		vector<pair<int, int> > cpy;
		for(int j = 0; j < m; j ++) {
			cpy.push_back({-cnt[j], j});
		}
		sort(cpy.begin(), cpy.end());
		for(int j = 0; j < halfCnt; j ++) {
			cnt[cpy[j].second] --;
			ans[i][cpy[j].second] = '+';
		}
		gotten ++;
		int curr = gotten;
		for(int j = 0; j < m; j ++) {
			if(cnt[j] * 2 > n) {
				curr ++;
			}
		}
		if(chkmax(ret, curr)) {
			for(int i = 0; i < n; i ++) {
				for(int j = 0; j < m; j ++) {
					tab[i][j] = ans[i][j];
				}
			}
		}
	}
	if(rev) {
		for(int i = 0; i < n; i ++) {
			for(int j = 0; j < m; j ++) {
				if(tab[i][j] == '-') {
					tab[i][j] = '+';
				} else {
					tab[i][j] = '-';
				}
			}
		}
		for(int i = 0; i < n; i ++) {
			for(int j = 0; j < m; j ++) {
				if(i < j) {
					swap(tab[i][j], tab[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(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 ++;
		}
	}
	//cout << a << " " << ret << endl; 
	cout << a << endl;
	for(int i = 0; i < n; i ++) {
		for(int j = 0; j < m; j ++) {
			cout << tab[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 getFast(int, int)':
stones.cpp:75:18: warning: unused variable 'opti' [-Wunused-variable]
   75 |  int gotten = 0, opti = 0;
      |                  ^~~~
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 Incorrect 1 ms 384 KB invalid character
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Wrong answer in test 2 1: 1 < 2
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB invalid character
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 109 ms 1608 KB Wrong answer in test 1 77: 37 < 77
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 164 ms 1656 KB Output is correct
2 Correct 336 ms 2680 KB Output is correct
3 Correct 295 ms 2296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB invalid character
2 Halted 0 ms 0 KB -