Submission #339519

# Submission time Handle Problem Language Result Execution time Memory
339519 2020-12-25T14:53:10 Z tengiz05 Red-blue table (IZhO19_stones) C++17
100 / 100
48 ms 2284 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1005;
char ans[N][N];
void Solve(){
  int n, m;
  cin >> n >> m;
  bool bad = false;
  if(n > m){
    swap(n, m);
    bad = true;
  }
  int i, j;
  int res;
  if(n <= 2){
    for(i=0;i<n;i++)
      for(j=0;j<m;j++)ans[i][j] = '-';
    res = m;
  }else if(n <= 4){
    for(i=0;i<(n+2)/2;i++)
      for(j=0;j<m;j++)ans[i][j] = '-';
    for(i=(n+2)/2;i<n;i++)
      for(j=0;j<m;j++)ans[i][j] = '+';
    res = m+((n-1)/2);
  }else {
    for(i=0;i<n;i++)
      for(j=0;j<m;j++)ans[i][j] = '-';
    int have = 0;
    i=0;
    j=0;
    vector<int> cnt(m+1,0);
    int need = (m)/2+1;
    int toans = 0;
    while(true){
      if(cnt[j] >= (n-1)/2)break;
      cnt[j]++;
      ans[i][j] = '+';
      j++;
      if(j == m)j=0;
      have++;
      if(have == need)i++,have=0, toans++;
    }res = toans + m;
  }
  cout << res << '\n';
  if(bad){
    for(i=0;i<n;i++)
      for(j=0;j<m;j++)
        if(ans[i][j] == '+')ans[i][j] = '-';
        else ans[i][j] = '+';
    for(j=0;j<m;j++){
      for(i=0;i<n;i++)
        cout << ans[i][j];
      cout << '\n';
    }
  }else {
    for(i=0;i<n;i++){
      for(j=0;j<m;j++)
        cout << ans[i][j];
      cout << '\n';
    }
  }
}
signed main(){
  int t;
  cin >> t;
  while(t--)Solve();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 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 404 KB Output is correct
3 Correct 3 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 1388 KB Output is correct
2 Correct 43 ms 2028 KB Output is correct
3 Correct 41 ms 2128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 1516 KB Output is correct
2 Correct 36 ms 1900 KB Output is correct
3 Correct 33 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 404 KB Output is correct
3 Correct 3 ms 364 KB Output is correct
4 Correct 4 ms 364 KB Output is correct
5 Correct 46 ms 1388 KB Output is correct
6 Correct 43 ms 2028 KB Output is correct
7 Correct 41 ms 2128 KB Output is correct
8 Correct 48 ms 1516 KB Output is correct
9 Correct 36 ms 1900 KB Output is correct
10 Correct 33 ms 1644 KB Output is correct
11 Correct 15 ms 620 KB Output is correct
12 Correct 41 ms 1644 KB Output is correct
13 Correct 40 ms 1644 KB Output is correct
14 Correct 27 ms 1388 KB Output is correct
15 Correct 44 ms 2284 KB Output is correct
16 Correct 32 ms 1900 KB Output is correct
17 Correct 16 ms 1132 KB Output is correct