답안 #339518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339518 2020-12-25T14:49:18 Z tengiz05 Red-blue table (IZhO19_stones) C++17
27 / 100
46 ms 1460 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)/2;
    int toans = 0;
    while(true){
      if(cnt[j] >= (m-1)/2)break;
      cnt[j]++;
      if(have == need)i++,have=0, toans++;
      if(i == n)break;
      ans[i][j] = '+';
      j++;
      if(j == m)j=0;
      have++;
    }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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 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 Incorrect 4 ms 364 KB in the table A+B is not equal to 34
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 1388 KB in the table A+B is not equal to 118
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 44 ms 1460 KB in the table A+B is not equal to 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 4 ms 364 KB in the table A+B is not equal to 34