Submission #683672

# Submission time Handle Problem Language Result Execution time Memory
683672 2023-01-19T05:18:23 Z dostigator Red-blue table (IZhO19_stones) C++17
38 / 100
2000 ms 131764 KB
//izho gold
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(),a.end()
#define pb push_back
#define vt vector
#define endl '\n'
#define Y second
#define X first
typedef long long ll;
typedef long double ld;
const ll mod=1e9+7;
const ll INF=1e18;
const int inf=1e9;
const int N=2e5+505;
const int M=1e3+10;
const int dx[]={0,0,1,-1};
const int dy[]={1,-1,0,0};

int n,m;

void solve(){
	cin>>n>>m;	
	if(min(n,m)<=3){
		if(n<=m){
			if(n==1){
				cout<<m<<endl;
				for(int i=1; i<=m; ++i)cout<<'-';
				cout<<endl;
				return;
			}if(n==2){
				cout<<m<<endl;
				for(int i=1; i<=m; ++i)cout<<'-';
				cout<<endl;
				for(int i=1; i<=m; ++i)cout<<'-';
				cout<<endl;
				return;
			}if(n==3){
				cout<<m+1<<endl;
				for(int i=1; i<=m; ++i)cout<<'-';
				cout<<endl;
				for(int i=1; i<=m; ++i)cout<<'+';
				cout<<endl;
				for(int i=1; i<=m; ++i)cout<<'-';
				cout<<endl;
				return;
			}
		}else{
			if(m==1){
				cout<<n<<endl;
				for(int i=1; i<=n; ++i)cout<<"+\n";
				return;
			}if(m==2){
				cout<<n<<endl;
				for(int i=1; i<=n; ++i)cout<<"++\n";
				return;
			}if(m==3){
				cout<<n+1<<endl;
				for(int i=1; i<=n; ++i)cout<<"+-+\n";
				return;
			}
		}
	}if(n%2==m%2 && n%2==0){
		int cnt=n;
		cnt+=n/2-1;
		cout<<cnt<<endl;
		for(int i=1; i<=n; ++i)for(int j=1; j<=m; ++j){
			if(j%2==0 || j+1==m){
				cout<<'+';
			}else{
				cout<<'-';
			}if(j==m)cout<<endl;
		}return;
	}
	if(n%2==m%2 && n%2==1){
		cout<<n+m-2<<endl;
		for(int i=1; i<n; ++i)for(int j=1; j<=m; ++j){
			if(j==m){
				cout<<'+'<<endl;
				continue;
			}if(i%2){
				if(j%2)cout<<'-';
				else cout<<'+';
			}else{
				if(j%2)cout<<'+';
				else cout<<'-';
			}
		}
		for(int i=1; i<=m; ++i){
			cout<<'-';
		}cout<<endl;
		return;
	}
	if(n*m<=36){
		vt<pair<int,int>>lst;
		char matrix[20][20];
		for(int mask=0; mask<(1<<(n*m)); ++mask){
			int x=1,y=1;
			for(int i=0; i<n*m; ++i){
				if(mask&(1<<i)){
					matrix[x][y]='+';
				}else matrix[x][y]='-';
				++y;
				if(y>m){
					++x;
					y=1;
				}
			}
			int cnt=0;
			for(int i=1; i<=n; ++i){
				int heh=0;
				for(int j=1; j<=m; ++j)heh+=(matrix[i][j]=='+');
				if(heh>m-heh)++cnt;
			}for(int j=1; j<=m; ++j){
				int heh=0;
				for(int i=1; i<=n; ++i)heh+=(matrix[i][j]=='-');
				if(heh>n-heh)++cnt;
			}lst.pb({cnt,mask});
		}sort(all(lst));
		int mask=lst.back().Y;
		cout<<lst.back().X<<endl;
		int x=1,y=1;
		for(int i=0; i<n*m; ++i){
			if(mask&(1<<i)){
				matrix[x][y]='+';
			}else matrix[x][y]='-';
			++y;
			if(y>m){
				++x;
				y=1;
			}
		}
		for(int i=1; i<=n; ++i){
			for(int j=1; j<=m; ++j){
				cout<<matrix[i][j];
			}cout<<endl;
		}return;
	}
}

int main(){
	//srand(time(0));
	//freopen("hotel.in","r",stdin);
	//freopen("hotel.out","w",stdout);
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int tt=1,lolol=0;
	cin>>tt;
	while(tt--) {
		//cout<<"Case "<<++lolol<<": ";
		solve();
	}
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:148:11: warning: unused variable 'lolol' [-Wunused-variable]
  148 |  int tt=1,lolol=0;
      |           ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Execution timed out 2085 ms 131764 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1220 KB Output is correct
2 Correct 21 ms 1124 KB Output is correct
3 Correct 20 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 1328 KB Wrong answer in test 24 24: 35 < 44
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 320 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Execution timed out 2085 ms 131764 KB Time limit exceeded
5 Halted 0 ms 0 KB -