Submission #1156409

#TimeUsernameProblemLanguageResultExecution timeMemory
1156409KaleemRazaSyedRed-blue table (IZhO19_stones)C++20
0 / 100
18 ms1352 KiB
#include<bits/stdc++.h>

using namespace std;

void solve()
{
  int n, m;
  cin >> n >> m;

  string sol[n];
  string A[n];
  int apb = 0;

  string s;
  for(int i = 0; i < m; i++) s += '-';
  for(int i = 0; i < n; i ++) sol[i] = s, A[i] = s;
  
  apb = n + (m - (m / 2 + 1));
  for(int i = 0; i < n; i ++)
    for(int j = 0; j < m/2 + 1; j++)
      sol[i][j] = '+';

  int ans = m + (n - (n / 2 + 1));
  if(apb < ans)
    {
      apb = ans;
      for(int i = 0; i < n; i ++) sol[i] = s;
      for(int j = 0; j < m; j ++)
	for(int i = 0; i < n - (n / 2 + 1); i++)
	  sol[i][j] = '+';
    }

  ans = n;
  for(int i = 0; i < n; i ++)
    {
      A[i] = s;
      for(int j = 0; j < m / 2 + 1; j++)
	A[i][(i % 2 ? j : m - j - 1)] = '+';
    }

  for(int j = 0; j < m; j ++)
    {
      int c = 0;
      for(int i = 0; i < n; i ++)
	{
	  if(A[i][j] == '+') c++;
	  else c--;
	}
      ans += (c < 0);
    }

  if(ans > apb)
    {
      apb = ans;
      for(int i = 0; i < n; i ++)
	sol[i] = A[i];
    }

  for(int i = 0; i < n; i ++) A[i] = s;

  ans = m;

  for(int j = 0; j < m ; j++)
    for(int i = 0; i < n / 2 + 1; i ++)
      A[(j % 2 ? i : n - i - 1)][j] = '+';


  for(int i = 0; i < n; i ++)
    {
      int c = 0;
      for(int j = 0; j < m; j ++)
	{
	  if(A[i][j] == '+') c++;
	  else c--;
	}
      ans += (c > 0);
    }

  if(ans > apb)
    {
      apb = ans;
      for(int i = 0; i < n; i ++)
	sol[i] = A[i];
    }

  cout << apb << endl;
  for(int i = 0; i < n; i ++)
    cout << sol[i] << endl;
  
  
}

int main()
{
  int t;
  cin >> t;
  while(t--)
    solve();
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...