답안 #169415

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
169415 2019-12-20T09:42:07 Z SamAnd Red-blue table (IZhO19_stones) C++17
100 / 100
70 ms 2268 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 1003;

int n, m;

char a[N][N];

int q[N];
void solv()
{
    memset(q, 0, sizeof q);
    scanf("%d%d", &n, &m);
    if (n < m)
    {
        for (int i = 0; i < n; ++i)
        {
            vector<pair<int, int> > v;
            for (int j = 0; j < m; ++j)
            {
                v.push_back(m_p(q[j], j));
            }
            sort(v.begin(), v.end());
            int qq = 0;
            for (int j = 0; j < m; ++j)
            {
                if (qq * 2 <= m && (n - q[v[j].second] - 1) * 2 > n)
                {
                    ++qq;
                    a[i][v[j].second] = '+';
                    ++q[v[j].second];
                }
                else
                    a[i][v[j].second] = '-';
            }
        }
    }
    else
    {
        for (int j = 0; j < m; ++j)
        {
            vector<pair<int, int> > v;
            for (int i = 0; i < n; ++i)
            {
                v.push_back(m_p(q[i], i));
            }
            sort(v.begin(), v.end());
            int qq = 0;
            for (int i = 0; i < n; ++i)
            {
                if (qq * 2 <= n && (m - q[v[i].second] - 1) * 2 > m)
                {
                    ++qq;
                    a[v[i].second][j] = '-';
                    ++q[v[i].second];
                }
                else
                    a[v[i].second][j] = '+';
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        int q = 0;
        for (int j = 0; j < m; ++j)
        {
            if (a[i][j] == '+')
                ++q;
        }
        if (q * 2 > m)
            ++ans;
    }
    for (int j = 0; j < m; ++j)
    {
        int q = 0;
        for (int i = 0; i < n; ++i)
        {
            if (a[i][j] == '-')
                ++q;
        }
        if (q * 2 > n)
            ++ans;
    }
    printf("%d\n", ans);
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
            putchar(a[i][j]);
        putchar('\n');
    }
}

int main()
{
    int tt;
    scanf("%d", &tt);
    while (tt--)
        solv();
    return 0;
}

Compilation message

stones.cpp: In function 'void solv()':
stones.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
stones.cpp: In function 'int main()':
stones.cpp:98:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &tt);
     ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 1472 KB Output is correct
2 Correct 59 ms 2080 KB Output is correct
3 Correct 59 ms 2168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 1528 KB Output is correct
2 Correct 56 ms 1912 KB Output is correct
3 Correct 51 ms 1660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 504 KB Output is correct
5 Correct 60 ms 1472 KB Output is correct
6 Correct 59 ms 2080 KB Output is correct
7 Correct 59 ms 2168 KB Output is correct
8 Correct 60 ms 1528 KB Output is correct
9 Correct 56 ms 1912 KB Output is correct
10 Correct 51 ms 1660 KB Output is correct
11 Correct 15 ms 632 KB Output is correct
12 Correct 52 ms 1892 KB Output is correct
13 Correct 55 ms 2040 KB Output is correct
14 Correct 42 ms 1784 KB Output is correct
15 Correct 70 ms 2268 KB Output is correct
16 Correct 50 ms 1916 KB Output is correct
17 Correct 23 ms 1304 KB Output is correct