Submission #382106

# Submission time Handle Problem Language Result Execution time Memory
382106 2021-03-26T11:58:37 Z vanic Red-blue table (IZhO19_stones) C++14
0 / 100
87 ms 1644 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(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:62:16: warning: 'naja' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |  for(int i=0; i<naja; i++){
      |               ~^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 364 KB Wrong answer
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 87 ms 1524 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 86 ms 1644 KB Wrong answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Wrong answer
2 Halted 0 ms 0 KB -