답안 #685632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
685632 2023-01-24T17:35:53 Z opPO Red-blue table (IZhO19_stones) C++17
11 / 100
2000 ms 1316 KB
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define f first
#define s second
#define pb push_back
#define ld long double
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vec vector

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
const ld eps = 1e-6;
const int mod = 1e9 + 7;
const int oo = 2e9;
const ll OO = 2e18;
const int N = 2e5 + 10;

int count(vec<vec<int>> &a)
{
    int n = sz(a), m = sz(a[0]);
    int res = 0;
    for (int i = 0; i < n; i++)
    {
        int r = 0, b = 0;
        for (int j = 0; j < m; j++)
        {
            if (a[i][j] == 1) r++;
            else b++;
        }
        res += r > b;
    }
    for (int j = 0; j < m; j++)
    {
        int r = 0, b = 0;
        for (int i = 0; i < n; i++)
        {
            if (a[i][j] == 1) r++;
            else b++;
        }
        res += b > r;
    }
    return res;
}

vec<vec<int>> transport(vec<vec<int>> &a)
{
    int n = sz(a), m = sz(a[0]);
    vec<vec<int>> b(m, vec<int>(n));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
            b[j][i] = a[i][j];
    }
    return b;
}

void solve()
{
    int n, m;
    cin >> n >> m;
    if (n % 2 && m % 2)
    {
        if (m == 1)
        {
            cout << n << "\n";
            for (int i = 0; i < n; i++) cout << "+\n";
            return;
        }
        if (n == 1) cout << m << "\n";
        else cout << n + m - 2 << "\n";
        for (int i = 0; i < n / 2; i++)
        {
            for (int j = 0; j <= m / 2; j++) cout << '+';
            for (int j = m / 2 + 1; j < m; j++) cout << '-';
            cout << "\n";
        }
        for (int i = 0; i < n / 2; i++)
        {
            cout << '+';
            for (int j = 1; j <= m / 2; j++) cout << '-';
            for (int j = m / 2 + 1; j < m; j++) cout << '+';
            cout << "\n";
        }
        for (int j = 0; j < m; j++) cout << '-';
        cout << "\n";
        return;
    }
    if (n == 2 && m == 2)
    {
        cout << "2\n--\n--\n";
        return;
    }
    if (n == m)
    {
        cout << n + m - 3 << "\n";
        for (int i = 0; i < (n - 1) / 2; i++)
        {
            for (int j = 0; j < m / 2; j++) cout << '+';
            for (int j = m / 2; j < m - 1; j++) cout << '-';
            cout << '+';
            cout << "\n";
        }
        for (int i = 0; i < (n - 1) / 2; i++)
        {
            cout << '+';
            for (int j = 1; j < m / 2; j++) cout << '-';
            for (int j = m / 2; j < m - 1; j++) cout << '+';
            cout << '+';
            cout << "\n";
        }
        for (int j = 0; j < m / 2; j++) cout << '+';
        for (int j = 1; j < m / 2; j++) cout << '-';
        cout << '+';
        cout << "\n";
        for (int j = 0; j < m; j++) cout << '-';
        cout << "\n";
        return;
    }
    vec<vec<int>> ans(n, vec<int>(m));
    for (int mask = 0; mask < (1LL << n * m); mask++)
    {
        vec<vec<int>> a(n, vec<int>(m));
        for (int i = 0; i < n * m; i++)
        {
            if ((mask >> i) & 1)
            {
                int x = i / m, y = i % m;
                a[x][y] = 1;
            }
        }
        if (count(a) > count(ans)) ans = a;
    }
    cout << count(ans) << "\n";
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (ans[i][j] == 1) cout << '+';
            else cout << '-';
        }
        cout << "\n";
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 3 ms 212 KB in the table A+B is not equal to 5
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2078 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 3 ms 212 KB in the table A+B is not equal to 5
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1316 KB Output is correct
2 Correct 18 ms 1220 KB Output is correct
3 Correct 17 ms 1076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 1292 KB in the table A+B is not equal to 45
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 3 ms 212 KB in the table A+B is not equal to 5
3 Halted 0 ms 0 KB -