답안 #173776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173776 2020-01-05T11:44:38 Z emil_physmath Red-blue table (IZhO19_stones) C++17
10 / 100
15 ms 1420 KB
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;

void Solve12(int n, int m)
{
    if (m <= 2 && n > m)
    {
        cout << n << '\n';
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < m; ++j)
                cout << "+";
            cout << '\n';
        }
    }
    else if (n <= 2)
    {
        cout << m << '\n';
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < m; ++j)
                cout << "-";
            cout << '\n';
        }
    }
}
int Value(const vector<string>& a)
{
    int n = a.size();
    int m = a[0].length();
    int res = 0;
    for (int i = 0; i < n; ++i)
        if (2 * count(a[i].begin(), a[i].end(), '+') > m)
            ++res;
    for (int j = 0; j < m; ++j)
    {
        int cnt = 0;
        for (int i = 0; i < n; ++i)
            if (a[i][j] == '-')
                ++cnt;
        if (2 * cnt > n)
            ++res;
    }
    return res;
}
bool SolveEvens(int n, int m)
{
    bool f = n < m;
    if (f)
        swap(n, m);
    vector<string> a(n, string(m, '-'));
    for (int i = 0; i < n; ++i)
        for (int j = m - 3; j < m; ++j)
            a[i][j] = '+';
    int block = (m / 2 + 1 - 3);
    int j = m - 4;
    for (int i = n - 1; i >= 0; --i)
    {
        for (int cnt = 0; cnt < block; ++cnt)
            a[i][(j - cnt + m - 3) % (m - 3)] = '+';
        j = (j - block + m - 3) % (m - 3);
    }
    if (f)
    {
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j)
                a[i][j] = (a[i][j] == '-' ? '+' : '-');
        swap(n, m);
        vector<string> temp(m, string(m, '-'));
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j)
                temp[i][j] = a[j][i];
        a.swap(temp);
    }
    int value;
    if ((value = Value(a)) < n + m - 4)
        return false;
    cout << Value(a) << '\n';
    for (int i = 0; i < n; ++i)
        cout << a[i] << '\n';
    cout << flush;
    return true;
}
void SolveUpTo5(int n, int m)
{
    vector<string> a(n, string(m, '-'));
    if (m <= 5 && n > m)
    {
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j)
                a[i][j] = (j < m / 2 ? '-' : '+');
            // a[i][1] = a[i][2] = '+';
    }
    else
    {
        for (int j = 0; j < m; ++j)
        {
            for (int i = 0; i < n; ++i)
                a[i][j] = (i < n / 2 ? '+' : '-');
            // a[1][j] = a[2][j] = '-';
        }
    }
    cout << Value(a) << '\n';
    for (int i = 0; i < n; ++i)
        cout << a[i] << '\n';
    cout << flush;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t;
    cin >> t;
    while (t--)
    {
        int n, m;
        cin >> n >> m;
        if (min(n, m) <= 2)
        {
            Solve12(n, m);
            continue;
        }
        if (min(n, m) <= 5)
        {
            SolveUpTo5(n, m);
            continue;
        }
        if (n % 2 == 0 && m % 2 == 0)
            if (SolveEvens(n, m))
                continue;
        vector<string> a(n, string(m, '+'));
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j)
                a[i][j] = ((i + j) % 2 ? '+' : '-');
        for (int i = 0; i < n; ++i)
            for (int j = m - 1 - (m + 1) % 2; j < m; ++j)
                a[i][j] = '+';
        for (int j = 0; j < m; ++j)
            for (int i = n - 1 - (n + 1) % 2; i < n; ++i)
                a[i][j] = '-';
        cout << Value(a) << '\n';
        for (int i = 0; i < n; ++i)
            cout << a[i] << '\n';
        cout << flush;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong answer in test 4 4: 2 < 5
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong answer in test 4 4: 2 < 5
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 1404 KB Wrong answer in test 7 5: 9 < 10
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 15 ms 1420 KB Wrong answer in test 5 5: 7 < 8
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Wrong answer in test 4 4: 2 < 5