Submission #344077

# Submission time Handle Problem Language Result Execution time Memory
344077 2021-01-05T06:08:19 Z Nurlykhan Red-blue table (IZhO19_stones) C++17
27 / 100
44 ms 1388 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1024;

int t;
int n, m;
bool a[N][N], ans[N][N];

int cnt() {
    int res = 0;
    for (int i = 0; i < n; i++) {
        int s = 0;
        for (int j = 0; j < m; j++) {
            if (a[i][j]) s++;
            else s--;
        }
        if (s > 0) res++;
    }
    for (int j = 0; j < m; j++) {
        int s = 0;
        for (int i = 0; i < n; i++) {
            if (a[i][j]) s++;
            else s--;
        }
        if (s < 0) res++;
    }
    return res;
}

void solve() {
    int mx = 0;
    for (int mask = 0; mask < (1 << (n * m)); mask++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if ((mask >> (i * m + j)) % 2) {
                    a[i][j] = 1;
                } else {
                    a[i][j] = 0;
                }
            }
        }
        int cur = cnt();
        if (cur > mx) {
            mx = cur;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    ans[i][j] = a[i][j];
                }
            }
        }
    }
    printf("%d\n", mx);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (ans[i][j])
                printf("+");
            else
                printf("-");
        }
        printf("\n");
    }
}

void tupo() {
    if (n <= m) {
        int ans = m + (n + 1) / 2 - 1;
        printf("%d\n", ans);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (i < (n + 1) / 2 - 1) printf("+");
                else printf("-");
            }
            printf("\n");
        }
    } else {
        int ans = n + (m + 1) / 2 - 1;
        printf("%d\n", ans);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (j < (m + 1) / 2 - 1) printf("-");
                else printf("+");
            }
            printf("\n");
        }
    }
}

int main() {
    scanf("%d", &t);
    while (t--) {
        scanf("%d%d", &n, &m);
        tupo();
    }

    return 0;
}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:91:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   91 |     scanf("%d", &t);
      |     ~~~~~^~~~~~~~~~
stones.cpp:93:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   93 |         scanf("%d%d", &n, &m);
      |         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory 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 3 ms 364 KB Wrong answer in test 5 29: 31 < 32
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 1388 KB Wrong answer in test 97 21: 107 < 116
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 1388 KB Wrong answer in test 24 24: 35 < 44
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 3 ms 364 KB Wrong answer in test 5 29: 31 < 32