Submission #947534

# Submission time Handle Problem Language Result Execution time Memory
947534 2024-03-16T10:53:27 Z dilanyan Red-blue table (IZhO19_stones) C++17
27 / 100
1029 ms 1368 KB
//-------------dilanyan------------\\ 
 
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
 
//------------------KarginDefines--------------------\\ 
 
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
 
 
//-------------------KarginConstants------------------\\ 
 
const ll mod = 1000000007;
const ll inf = 2e9;
 
//-------------------KarginCode------------------------\\ 
 
const int N = 1005;

char a[N][N], ans[N][N];
int cnt = 0;
int dx[4] = { 1,-1,0,0 };
int dy[4] = { 0,0,1,-1 };

int n, m;
int A = 0, B = 0;

void dfs(int sx, int sy,char c) {
    a[sx][sy] = c;
    cnt++;
    for (int i = 0;i < 4;i++) {
        int x = sx + dx[i], y = sy + dy[i];
        if (x >= 1 && x <= n && y >= 1 && y <= m) {
            if (a[x][y] == '0') {
                dfs(x, y, '+');
                dfs(x, y, '-');
            }
        }
    }
    if (cnt == n * m) {
        int ax = 0, bx = 0;
        for (int i = 1;i <= n;i++) {
            int r = 0, b = 0;
            for (int j = 1;j <= m;j++) {
                if (a[i][j] == '+') r++;
                else b++;
            }
            if (r > b) ax++;
        }
        for (int i = 1;i <= m;i++) {
            int r = 0, b = 0;
            for (int j = 1;j <= n;j++) {
                if (a[j][i] == '+') r++;
                else b++;
            }
            if (b > r) bx++;
        }
        if (ax + bx > A + B) {
            A = ax, B = bx;
            for (int i = 1;i <= n;i++) {
                for (int j = 1;j <= m;j++) {
                    ans[i][j] = a[i][j];
                }
            }
        }
    }
    a[sx][sy] = '0';
    cnt--;
}

void KarginSolve() {
    cin >> n >> m;
    if (n <= 4 && m <= 4) {
        A = 0, B = 0;
        for (int i = 1;i <= n;i++) {
            for (int j = 1;j <= m;j++) {
                a[i][j] = '0';
                ans[i][j] = '0';
            }
        }
        dfs(1, 1, '+');
        dfs(1, 1, '-');
        cout << A + B << '\n';
        for (int i = 1;i <= n;i++) {
            for (int j = 1;j <= m;j++) {
                cout << ans[i][j];
            }
            cout << '\n';
        }
    }
    else if (min(n, m) <= 3) {
        if (n < m) {
            if (n == 1) {
                cout << m << '\n';
                for (int i = 1;i <= m;i++) cout << '-';
                cout << '\n';
            }
            else if (n == 2) {
                cout << m << '\n';
                for (int i = 1;i <= n;i++) {
                    for (int j = 1;j <= m;j++) {
                        cout << '-';
                    }
                    cout << '\n';
                }
            }
            else {
                cout << m + 1 << '\n';
                for (int i = 1;i <= m;i++) cout << '+';
                cout << '\n';
                for (int i = 1;i <= 2;i++) {
                    for (int j = 1;j <= m;j++) {
                        cout << '-';
                    }
                    cout << '\n';
                }
            }
        }
        else {
            if (m == 1) {
                cout << n << '\n';
                for (int i = 1;i <= n;i++) cout << "+\n";
            }
            else if (m == 2) {
                cout << n << '\n';
                for (int i = 1;i <= n;i++) {
                    for (int j = 1;j <= m;j++) {
                        cout << '+';
                    }
                    cout << '\n';
                }
            }
            else {
                cout << n + 1 << '\n';
                for (int i = 1;i <= n;i++) {
                    for (int j = 1;j <= m;j++) {
                        if (j < m) cout << '+';
                        else cout << '-';
                    }
                    cout << '\n';
                }
            }
        }
    }
    else {
        if (n < m) {
            cout << m + n / 2 - (n % 2 == 0) << '\n';
            for (int i = 1;i <= n;i++) {
                for (int j = 1;j <= m;j++) {
                    if (i <= n / 2 - (n % 2 == 0)) {
                        cout << '+';
                    }
                    else cout << '-';
                }
                cout << '\n';
            }
        }
        else {
            cout << n + m / 2 - (m % 2 == 0) << '\n';
            for (int i = 1;i <= n;i++) {
                for (int j = 1;j <= m;j++) {
                    if (j <= m / 2 - (m % 2 == 0)) {
                        cout << '-';
                    }
                    else cout << '+';
                }
                cout << '\n';
            }
        }
    }
}
 
int main() {
    //Usaco
    Kargin;
    int test = 1;
    cin >> test;
    while (test--) {
        KarginSolve();
    }
    return 0;
}

Compilation message

stones.cpp:1:1: warning: multi-line comment [-Wcomment]
    1 | //-------------dilanyan------------\\
      | ^
stones.cpp:8:1: warning: multi-line comment [-Wcomment]
    8 | //------------------KarginDefines--------------------\\
      | ^
stones.cpp:22:1: warning: multi-line comment [-Wcomment]
   22 | //-------------------KarginConstants------------------\\
      | ^
stones.cpp:27:1: warning: multi-line comment [-Wcomment]
   27 | //-------------------KarginCode------------------------\\
      | ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 514 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 514 ms 440 KB Output is correct
3 Correct 20 ms 344 KB Output is correct
4 Incorrect 1029 ms 452 KB Wrong answer in test 5 29: 31 < 32
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 1368 KB Wrong answer in test 97 21: 107 < 116
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 543 ms 1364 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 344 KB Output is correct
2 Correct 514 ms 440 KB Output is correct
3 Correct 20 ms 344 KB Output is correct
4 Incorrect 1029 ms 452 KB Wrong answer in test 5 29: 31 < 32
5 Halted 0 ms 0 KB -