Submission #330841

# Submission time Handle Problem Language Result Execution time Memory
330841 2020-11-26T17:40:52 Z vitkishloh228 Red-blue table (IZhO19_stones) C++14
100 / 100
17 ms 1388 KB
#include <iostream>
#include <vector>
 
using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
 
bool valid(int red, int blue, int n, int m) {
  if(red == 0 || blue == 0)
    return true;
  int part = std::max(0, (m + 2) / 2 - (m - blue));
  int part2 = std::max(0, (n + 2) / 2 - (n - red));
  
  if(part <= blue) {
    int slots = (part * red + (blue - 1)) / blue;
    if(slots + part2 <= red)
      return true;
  }
  return false;
}
 
void solve() {
  int n, m;
  std::cin >> n >> m;
  int x = 0, y = 0;
  for(int i = 0; i <= n; i++)
    for(int j = 0; j <= m; j++)
      if(valid(i, j, n, m) == true && x + y < i + j) {
        x = i;
        y = j;
      }
  std::cout << x + y << '\n';
  int ptr = 0; 
  int part = std::max(0, (m + 2) / 2 - (m - y));
  
  for(int i = 0; i < x; i++) {
    std::string s;
    s.resize(m);
    for(int j = 0; j < m; j++)
      s[j] = '-';
    for(int j = 0; j < part; j++) {
      s[ptr] = '+';
      ptr = (ptr + 1) % y;
    }
    for(int j = y; j < m; j++)
      s[j] = '+';
    std::cout << s << '\n';
  }
  for(int i = x; i < n; i++) {
    std::string s;
    s.resize(m);
    for(int j = 0; j < m; j++)
      s[j] = '-';
    std::cout << s << '\n';
  }
}
 
int main() {
  int t;
  std::cin >> t;
  for(int testcase = 1; testcase <= t; testcase++)
    solve();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1388 KB Output is correct
2 Correct 12 ms 1260 KB Output is correct
3 Correct 12 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1388 KB Output is correct
2 Correct 11 ms 1132 KB Output is correct
3 Correct 10 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 3 ms 364 KB Output is correct
5 Correct 17 ms 1388 KB Output is correct
6 Correct 12 ms 1260 KB Output is correct
7 Correct 12 ms 1132 KB Output is correct
8 Correct 15 ms 1388 KB Output is correct
9 Correct 11 ms 1132 KB Output is correct
10 Correct 10 ms 1132 KB Output is correct
11 Correct 7 ms 620 KB Output is correct
12 Correct 11 ms 1132 KB Output is correct
13 Correct 11 ms 1132 KB Output is correct
14 Correct 9 ms 1004 KB Output is correct
15 Correct 14 ms 1388 KB Output is correct
16 Correct 10 ms 1004 KB Output is correct
17 Correct 6 ms 620 KB Output is correct