답안 #599009

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

char table[1024][1024];
void build(int n, int m) {
  // n >= m for sure
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      table[i][j] = j < (m - 1) / 2 ? '-' : '+';
    }
    table[i][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:51:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |   scanf("%d", &t);
      |   ~~~~~^~~~~~~~~~
stones.cpp:54:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |     scanf("%d%d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Wrong answer in test 5 29: 31 < 32
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 1476 KB Wrong answer in test 97 21: 107 < 116
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 1364 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 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Wrong answer in test 5 29: 31 < 32
5 Halted 0 ms 0 KB -