답안 #599046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
599046 2022-07-19T09:29:33 Z Plurm Red-blue table (IZhO19_stones) C++11
11 / 100
7 ms 2980 KB
#include <bits/stdc++.h>
using namespace std;

char table[1024][1024];
void build(int n, int m) {
  if (n == 1) {
    for (int j = 0; j < m; j++)
      table[0][j] = '-';
    table[0][m] = '\0';
    return;
  } else if (m == 1) {
    for (int i = 0; i < n; i++) {
      table[i][0] = '+';
      table[i][1] = '\0';
    }
    return;
  } else if (n % 2 == 0) {
    for (int i = 0; i <= n / 2; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = '-';
      }
      table[i][m] = '\0';
    }
    for (int i = n / 2 + 1; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = '+';
      }
      table[i][m] = '\0';
    }
    return;
  } else if (m % 2 == 0) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j <= m / 2; j++) {
        table[i][j] = '+';
      }
      for (int j = m / 2; j < m; j++) {
        table[i][j] = '-';
      }
      table[i][m] = '\0';
    }
    return;
  }
  for (int i = 0; i < n / 2; i++) {
    for (int j = 0; j < m - 1; j++) {
      table[i][j] = j < (m - 1) / 2 ? '-' : '+';
    }
    table[i][m - 1] = '+';
    table[i][m] = '\0';
  }
  for (int i = n / 2; i < n - 1; i++) {
    for (int j = 0; j < m - 1; j++) {
      table[i][j] = j < (m - 1) / 2 ? '+' : '-';
    }
    table[i][m - 1] = '+';
    table[i][m] = '\0';
  }
  for (int j = 0; j < m - 1; j++)
    table[n - 1][j] = '-';
  table[n - 1][m - 1] = '+';
  table[n - 1][m] = '\0';
}
char tmp[1024][1024];
void transpose(int n, int m) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      tmp[j][i] = '+' ^ '-' ^ table[i][j];
    }
  }
  for (int j = 0; j < m; j++)
    tmp[j][n] = '\0';
  for (int i = 0; i < m; i++) {
    strcpy(table[i], tmp[i]);
  }
}
int count(int n, int m) {
  int cc = 0;
  for (int i = 0; i < n; i++) {
    int uc = 0;
    for (int j = 0; j < m; j++) {
      if (table[i][j] == '+')
        uc++;
    }
    if (uc > m - uc)
      cc++;
  }
  for (int j = 0; j < m; j++) {
    int uc = 0;
    for (int i = 0; i < n; i++) {
      if (table[i][j] == '-')
        uc++;
    }
    if (uc > n - uc)
      cc++;
  }
  return cc;
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m;
    scanf("%d%d", &n, &m);
    if (n > m) {
      build(m, n);
      transpose(m, n);
    } else {
      build(n, m);
    }
    printf("%d\n", count(n, m));
    for (int i = 0; i < n; i++) {
      printf("%s\n", table[i]);
    }
  }
  return 0;
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:99:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |   scanf("%d", &t);
      |   ~~~~~^~~~~~~~~~
stones.cpp:102:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Wrong answer in test 4 3: 2 < 5
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Wrong answer in test 4 3: 2 < 5
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Wrong answer in test 4 3: 2 < 5
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1492 KB Output is correct
2 Correct 6 ms 2516 KB Output is correct
3 Correct 7 ms 2980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1460 KB Wrong answer in test 24 24: 35 < 44
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Wrong answer in test 4 3: 2 < 5
3 Halted 0 ms 0 KB -