답안 #334103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334103 2020-12-08T10:42:49 Z boykut Red-blue table (IZhO19_stones) C++14
27 / 100
4 ms 364 KB
#include <bits/stdc++.h>

using namespace std;

string s[]={};
char a[1000][1000], res[1000][1000];
int ans;

void rec(int x, int y, char c, int n, int m) {
  a[x][y]=c;
  if(x==n-1&&y==m-1) {
    int A=0,B=0;
    for(int i=0;i<n;i++){
      int c=0;
      for(int j=0;j<m;j++){
        if(a[i][j]=='+')c++;
      }
      if(c>m/2)A++;
    }
    for(int j=0;j<m;j++){
      int c=0;
      for(int i=0;i<n;i++){
        if(a[i][j]=='-')c++;
      }
      if(c>n/2)B++;
    }
    if(A+B>ans){
      ans=A+B;
      for(int i=0;i<n;i++)
        for(int j=0;j<m;j++)
          res[i][j]=a[i][j];
    }
    return;
  }
  if(y+1<m){
    rec(x,y+1,'-',n,m);
    rec(x,y+1,'+',n,m);
  } else if(x+1<n){
    rec(x+1,0,'-',n,m);
    rec(x+1,0,'+',n,m);
  }
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t, flag = 1;
  cin >> t;
  if (t > 16) flag = 0;
  int x[t], y[t];
  for (int i = 0; i < t; i++) {
    cin >> x[i] >> y[i];
    if(x[i] > 4 || y[i] > 4)
      flag = 0;
  }
  for (int p = 0; p < t; p++) {
    int n, m;
    n = x[p], m = y[p];
    if (flag) {
      ans=0;
      rec(0,0,'-',n,m);
      rec(0,0,'+',n,m);
      cout<<ans<<'\n';
      for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
          cout<<res[i][j];
        cout<<'\n';
      }
      continue;
    }
    if(n==1){
      cout<<m<<'\n';
      for(int i=0;i<m;i++)
        cout<<'-';
      cout<<'\n';
      continue;
    }
    if(m==1){
      cout<<n<<'\n';
      for(int i=0;i<n;i++)
        cout<<'+'<<'\n';
      continue;
    }
    if(n==2){
      cout<<m<<'\n';
      for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
          cout<<'-';
        cout<<'\n';
      }
      continue;
    }
    if(m==2){
      cout<<n<<'\n';
      for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
          cout<<'+';
        cout<<'\n';
      }
      continue;
    }
    if(n==3){
      cout<<m+1<<'\n';
      for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
          if(i%2==0)cout<<'-';
          else cout<<'+';
        cout<<'\n';
      }
      continue;
    }
    if(m==3){
      cout<<n+1<<'\n';
      for(int i=0;i<n;i++)
        cout<<"+-+\n";
      continue;
    }
    if(n==4){
      if(m==5){
        cout<<6<<'\n';
        for(int i=0;i<n;i++){
          for(int j=0;j<m;j++)
            if(j&1)cout<<'-';
            else cout<<'+';
          cout<<'\n';
        }
        continue;
      }else{
        cout<<m<<'\n';
        for(int i=0;i<n;i++){
          for(int j=0;j<m;j++)
            cout<<'-';
          cout<<'\n';
        }
        continue;
      }
    }
    if(n==4&&m==4){
      cout<<5<<'\n';
      for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
          if(i==n-1&&j==m-1)cout<<'+';
          else if(i==n-1&&j==m-2)cout<<'+';
          else if(i==n-2&&j==m-3)cout<<'+';
          else cout<<'-';
        cout<<'\n';
      }
      continue;
    }
    if(m==4){
      if(m==5){
        cout<<6<<'\n';
        for(int i=0;i<n;i++){
          for(int j=0;j<m;j++)
            if(i&1)cout<<'+';
            else cout<<'-';
          cout<<'\n';
        }
        continue;
      }else{
        cout<<n<<'\n';
        for(int i=0;i<n;i++){
          for(int j=0;j<m;j++)
            cout<<'+';
          cout<<'\n';
        }
        continue;
      }
    }
    if(n==5){
      cout<<m+2<<'\n';
      for(int i=0;i<n;i++) {
        for(int j=0;j<m;j++)
          if(i<n/2+1)cout<<'-';
          else cout<<'+';
        cout<<'\n';
      }
      continue;
    }
    if(m==5){
      cout<<n+2<<'\n';
      for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
          if(j<m/2+1)cout<<'+';
          else cout<<'-';
        cout<<'\n';
      }
      continue;
    }
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 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 4 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Incorrect 2 ms 364 KB Wrong answer in test 4 25: 25 < 26
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Wrong answer
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Wrong answer
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 4 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Incorrect 2 ms 364 KB Wrong answer in test 4 25: 25 < 26