Submission #961160

# Submission time Handle Problem Language Result Execution time Memory
961160 2024-04-11T15:23:16 Z pcc Red-blue table (IZhO19_stones) C++17
38 / 100
521 ms 4084 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>

bool trivial(int r,int c){
	if(r == 1){
		cout<<c<<'\n';
		for(int i = 0;i<c;i++)cout<<'-';
		cout<<'\n';
		return true;
	}
	else if(c == 1){
		cout<<r<<'\n';
		for(int i = 0;i<r;i++)cout<<'+'<<'\n';
		return true;
	}
	else if(r == 2){
		cout<<c<<'\n';
		for(int i = 0;i<r;i++){
			for(int j = 0;j<c;j++)cout<<'-';
			cout<<'\n';
		}
		return true;
	}
	else if(c == 2){
		cout<<r<<'\n';
		for(int i = 0;i<r;i++){
			for(int j = 0;j<c;j++)cout<<'+';
			cout<<'\n';
		}
		return true;
	}
	else return false;
}

namespace S1{

	int ans[22][22],C[22][22];
	int row[22],col[22];

	void calc(int r,int c){
		int big = 0,cnt = 0;
		for(int i = 0;i<(1<<(r*c));i++){
			for(int j = 0;j<r;j++)row[j] = 0;
			for(int j = 0;j<c;j++)col[j] = 0;
			for(int j = 0;j<r;j++){
				for(int k = 0;k<c;k++){
					if(i&(1<<(j*c+k)))row[j]++,col[k]++;
				}
			}
			int tc = 0;
			for(int j = 0;j<r;j++){
				tc += (row[j]>c-row[j]);
			}
			for(int j = 0;j<c;j++){
				tc += (r-col[j]>col[j]);
			}
			if(tc>cnt)cnt = tc,big = i;
		}
		ans[r][c] = cnt;
		C[r][c] = big;
	}

	void prep(){
		for(int i = 1;i<=5;i++){
			for(int j = 1;i*j<=20;j++)calc(i,j);
		}
		return;
	}

	void solve(int r,int c){
		if(trivial(r,c))return;
		string s[r];
		for(int i = 0;i<r;i++){
			for(int j = 0;j<c;j++){
				if(C[r][c]&(1<<(i*c+j)))s[i] += '+';
				else s[i] += '-';
			}
		}
		cout<<ans[r][c]<<'\n';
		for(auto &i:s)cout<<i<<'\n';
		return;
	}
}

namespace S2{
	void solve(int r,int c){
		if(trivial(r,c))return;
		vector<vector<int>> v(r,vector<int>(c,-1));
		if(r == 3){
			for(int i = 0;i<c/2+1;i++)v[0][i] = 1;
		}
		else{
			for(auto &i:v)for(auto &j:i)j = -j;
			for(int i = 0;i<r/2+1;i++)v[i][0] = -1;
		}
		cout<<r+c-2<<'\n';
		for(auto &i:v){
			for(auto &j:i)cout<<(j==1?'+':'-');
			cout<<'\n';
		}
		return;
	}
}

namespace S4{
	void solve(int r,int c){
		if(trivial(r,c))return;
		bool f = false;
		if(r>c)f = true,swap(r,c);
		vector<vector<int>> v(r,vector<int> (c,-1));
		for(int i = 0;i<r/2;i++){
			for(int j = 0;j<=c/2;j++)v[i][j] = v[r-1-i][c-1-j] = 1;
		}
		int cnt = 0;
		cout<<r+c-1-(min(r,c)!=1)<<'\n';
		if(f){
			for(int i = 0;i<c;i++){
				for(int j = 0;j<r;j++)cout<<(-v[j][i] == 1?'+':'-');
				cout<<'\n';
			}
		}
		else{
			for(int i = 0;i<r;i++){
				for(int j = 0;j<c;j++)cout<<(v[i][j] == 1?'+':'-');
				cout<<'\n';
			}
		}
		return;
	}
}

namespace S5{
	void solve(int r,int c){
		if(trivial(r,c))return;
		vector<vector<int>> v(r,vector<int>(c,1));
		for(int i = 0;i<r/2+1;i++){
			for(int j = c/2+1;j<c;j++)v[i][j] = -1;
		}
		for(int i = r/2+1;i<r;i++){
			for(int j = 0;j<c/2-1;j++)v[i][j] = -1;
		}
		cout<<r+c/2-1<<'\n';

		if(r == 12)v[0][0] = -1;

		for(int i = 0;i<r;i++){
			for(int j = 0;j<c;j++)cout<<(v[i][j] == 1?'+':'-');
			cout<<'\n';
		}
		return;
	}
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	S1::prep();
	int t;
	cin>>t;
	while(t--){
		int r,c;
		cin>>r>>c;
		if(r<=4&&c<=4)S1::solve(r,c);
		else if(min(r,c)<=3)S2::solve(r,c);
		else if((r&1)&&(c&1)) S4::solve(r,c);
		else if(r==c)S5::solve(r,c);
	}
	return 0;
}

Compilation message

stones.cpp: In function 'void S4::solve(int, int)':
stones.cpp:121:7: warning: unused variable 'cnt' [-Wunused-variable]
  121 |   int cnt = 0;
      |       ^~~
# Verdict Execution time Memory Grader output
1 Correct 478 ms 592 KB Output is correct
2 Correct 474 ms 432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 482 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 478 ms 592 KB Output is correct
2 Correct 474 ms 432 KB Output is correct
3 Correct 482 ms 428 KB Output is correct
4 Incorrect 479 ms 440 KB Wrong answer
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 491 ms 1452 KB Output is correct
2 Correct 502 ms 3504 KB Output is correct
3 Correct 521 ms 4084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 508 ms 1496 KB Wrong answer in test 24 24: 35 < 44
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 478 ms 592 KB Output is correct
2 Correct 474 ms 432 KB Output is correct
3 Correct 482 ms 428 KB Output is correct
4 Incorrect 479 ms 440 KB Wrong answer
5 Halted 0 ms 0 KB -