답안 #168755

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168755 2019-12-15T18:36:27 Z RafaelSus Red-blue table (IZhO19_stones) C++14
28 / 100
37 ms 4088 KB
#include <bits/stdc++.h>

using namespace std;
const long long mod = 1e9 + 7;

int main(){

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int t;
  cin >> t;
  while (t-- > 0){
    int n, m;
    cin >> n >> m;
    
    ///////////////////OK
    if (n == 1){
      cout << m << '\n';
      for (int i = 0; i < m; i++){
        cout << "-";
      }
      cout << '\n';
      continue;
    }else if (m == 1){
      cout << n << '\n';
      for (int i = 0; i < n; i++){
        cout << "+\n";
      }
      continue;
    }//////////////////OK
    
    if (n >= m){
      //vector <vector <char>> g(n, vector <char>(m, '-'));
      int g[n + 10][m + 10];
      for (int i = 0; i < n - (n % 4 == 0 && n != 4); i++){
        g[i][0] = 1;
        g[i][m - 1] = 1;
        if (m % 2 == 0)g[i][1] = 1;
      }
      int x = (m - 2) / 2;
      vector <int> vec(m, 0);
      if (m % 2 == 0) x = (m - 3) / 2;
      int mx = 0;
      for (int i = 0; i < x; i++){
        vec[i * 2] = 1;
        mx = i * 2;
      } 
 
      int low = 0, high = mx;
      for (int i = 0; i < n - (n % 4 == 0 && n != 4); i++){
        int h = 1;
        if (m % 2 == 0) h = 2;
        for (int j = h; j < m - 1; j++){
          if (vec[j - 1 - h + 1] == 1)g[i][j] = 1;
          else g[i][j] = 0;
        }
        vector <int> used(m);
        //for (auto x : vec) cout << x << ' ';
        //cout << '\n';
        /*if (m % 2 == 0 && (i == n - 2 || i == n - 3)){
          for (int j = 0; j <= m - 2; j++)vec[j] = 0;
          continue;
        }*/
        int hh = 2;
        if (m % 2 == 0) hh = 3;
        for (int j = 0; j <= m - hh; j++){
          if (vec[j] == 1 && !used[j]){
            vec[j] = 0;
            if (j + 1 < m - hh){
              vec[j + 1] = 1;
              used[j + 1] = 1;
            }else{
              vec[0] = 1;
              used[0] = 1;
            }
          }
        }
      }
      if (n % 4 == 0 && n != 4){
        for (int i = 0; i < m; i++){
          g[n - 1][i] = 0;
        }
      }
      //////////////////////
      //CHECK///////////////
      //////////////////////
      int answ = 0;
      for (int i = 0; i < n; i++){
        int h = 0;
        for (int j = 0; j < m; j++){
          if (g[i][j] == 1)h++;
        }
        if (h > (m - h))answ++;
      }
      for (int i = 0; i < m; i++){
        int h = 0;
        for (int j = 0; j < n; j++){
          if (g[j][i] == 0)h++;
        }
        if (h > (n - h))answ++;
      }
      cout << answ << '\n';
      for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
          if (g[i][j] == 1)cout << "+";
          else cout << "-";
          //cout << g[i][j];
        }
        cout << '\n';
      }
    }
    
    else{
     
     
      //vector <vector <char>> g(n, vector <char>(m, '-'));
      int g[n + 10][m + 10];
      for (int i = 0; i < m - (m % 4 == 0 && m != 4); i++){
        g[0][i] = 0;
        g[n - 1][i] = 0;
        if (n % 2 == 0)g[1][i] = 0;
      }
      int x = (n - 2) / 2;
      if (n % 2 == 0) x = (n - 3) / 2;
      vector <int> vec(n, 0);
      int mx = 0;
      for (int i = 0; i < x; i++){
        vec[i * 2] = 1;
        mx = i * 2;
      } 
 
      int low = 0, high = mx;
      for (int i = 0; i < m - (m % 4 == 0 && m != 4); i++){
        int h = 1;
        if (n % 2 == 0)h = 2;
        for (int j = h; j < n - 1; j++){
          if (vec[j - 1 - h + 1] == 1)g[j][i] = 0;
          else g[j][i] = 1;
        }
        vector <int> used(n);
        //for (auto x : vec) cout << x << ' ';
        //cout << '\n';
        /*if (n % 2 == 0 && (i == m - 2 || i == m - 3)){
          for (int j = 0; j <= n - 2; j++)vec[j] = 0;
          continue;
        }*/
        int hh = 2;
        if (n % 2 == 0) hh = 3;
        for (int j = 0; j <= n - hh; j++){
          if (vec[j] == 1 && !used[j]){
            vec[j] = 0;
            if (j + 1 < n - hh){
              vec[j + 1] = 1;
              used[j + 1] = 1;
            }else{
              vec[0] = 1;
              used[0] = 1;
            }
          }
        }
      } 
      
      if (m % 4 == 0 && m != 4){
        for (int i = 0; i < n; i++){
          g[i][m - 1] = 1;
        }
      }
      //////////////////////
      //CHECK///////////////
      //////////////////////
      int answ = 0;
      for (int i = 0; i < n; i++){
        int h = 0;
        for (int j = 0; j < m; j++){
          if (g[i][j] == 1)h++;
        }
        if (h > (m - h))answ++;
      }
      for (int i = 0; i < m; i++){
        int h = 0;
        for (int j = 0; j < n; j++){
          if (g[j][i] == 0)h++;
        }
        if (h > (n - h))answ++;
      }
      cout << answ << '\n';
      for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
          if (g[i][j] == 1) cout << "+";
          else cout << "-";
          //cout << g[i][j];
        }
        cout << '\n';
      }
    }
  }
  return 0;
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:51:11: warning: unused variable 'low' [-Wunused-variable]
       int low = 0, high = mx;
           ^~~
stones.cpp:51:20: warning: unused variable 'high' [-Wunused-variable]
       int low = 0, high = mx;
                    ^~~~
stones.cpp:134:11: warning: unused variable 'low' [-Wunused-variable]
       int low = 0, high = mx;
           ^~~
stones.cpp:134:20: warning: unused variable 'high' [-Wunused-variable]
       int low = 0, high = mx;
                    ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 376 KB Wrong answer in test 20 2: 19 < 20
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Incorrect 3 ms 376 KB Wrong answer in test 20 2: 19 < 20
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 1400 KB Output is correct
2 Correct 34 ms 3832 KB Output is correct
3 Correct 31 ms 4088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 34 ms 1400 KB Wrong answer in test 46 46: 69 < 88
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Incorrect 3 ms 376 KB Wrong answer in test 20 2: 19 < 20