Submission #382109

# Submission time Handle Problem Language Result Execution time Memory
382109 2021-03-26T12:04:06 Z vanic Red-blue table (IZhO19_stones) C++14
100 / 100
90 ms 2412 KB
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <set>

using namespace std;

const int maxn=1005;

int n, m;
char c[maxn][maxn];
set < pair < int, int > > s;

int prebroji(){
	int sum=0;
	int br;
	for(int i=0; i<n; i++){
		br=0;
		for(int j=0; j<m; j++){
			if(c[i][j]=='+'){
				br++;
			}
		}
		if(br>m/2){
			sum++;
		}
	}
	for(int j=0; j<m; j++){
		br=0;
		for(int i=0; i<n; i++){
			if(c[i][j]=='-'){
				br++;
			}
		}
		if(br>n/2){
			sum++;
		}
	}
	return sum;
}

void solve(){
	cin >> n >> m;
	int c1=(n+2)/2;
	int c2=(m+2)/2;
	int uk=n*m;
	int sol=0;
	int naja, najb;
	int a, b;
	for(int i=0; i<=m; i++){
		a=i;
		b=min(n, (uk-c1*a)/c2);
		if(n>m && a+b>sol){
			sol=a+b;
			naja=a;
			najb=b;
		}
		else if(n<=m && a+b>=sol){
			sol=a+b;
			naja=a;
			najb=b;
		}
	}
//	cout << sol << '\n';
//	cout << naja << ' ' << najb << endl;
	for(int i=0; i<naja; i++){
		s.insert({0, i});
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			c[i][j]='+';
		}
	}
	int cor;
	for(int i=0; i<najb; i++){
		for(int j=0; j<(m-1)/2; j++){
			cor=s.begin()->second;
			s.insert({s.begin()->first+1, s.begin()->second});
			s.erase(s.begin());
			c[i][cor]='-';
		}
	}
	for(int i=najb; i<n; i++){
		for(int j=0; j<m; j++){
			c[i][j]='-';
		}
	}
	cout << prebroji() << '\n';
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cout << c[i][j];
		}
		cout << '\n';
	}
	s.clear();
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while(t--){
		solve();
	}
	return 0;
}

Compilation message

stones.cpp: In function 'void solve()':
stones.cpp:49:12: warning: 'najb' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |  int naja, najb;
      |            ^~~~
stones.cpp:67:16: warning: 'naja' may be used uninitialized in this function [-Wmaybe-uninitialized]
   67 |  for(int i=0; i<naja; i++){
      |               ~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 4 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 1560 KB Output is correct
2 Correct 77 ms 2028 KB Output is correct
3 Correct 74 ms 2156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 1516 KB Output is correct
2 Correct 74 ms 1900 KB Output is correct
3 Correct 70 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 4 ms 492 KB Output is correct
5 Correct 83 ms 1560 KB Output is correct
6 Correct 77 ms 2028 KB Output is correct
7 Correct 74 ms 2156 KB Output is correct
8 Correct 84 ms 1516 KB Output is correct
9 Correct 74 ms 1900 KB Output is correct
10 Correct 70 ms 1644 KB Output is correct
11 Correct 18 ms 620 KB Output is correct
12 Correct 67 ms 2028 KB Output is correct
13 Correct 70 ms 2156 KB Output is correct
14 Correct 53 ms 1772 KB Output is correct
15 Correct 90 ms 2412 KB Output is correct
16 Correct 68 ms 1900 KB Output is correct
17 Correct 28 ms 1388 KB Output is correct