Submission #526634

# Submission time Handle Problem Language Result Execution time Memory
526634 2022-02-15T19:24:20 Z nitr0gen Red-blue table (IZhO19_stones) C++14
17 / 100
2000 ms 332 KB
#include <bits/stdc++.h>
using namespace std;

int ans, n, m;
char a[100][100];
bool ok;

int check() {
    int cnta = 0, cntb = 0;
    for(int i = 0; i < n; i++) {
        int cnt = 0;
        for(int j = 0; j < m; j++) {
            if(a[i][j] == '+') cnt++;
        }
        if(cnt * 2 > m) cnta++;
    }
    for(int j = 0; j < m; j++) {
        int cnt = 0;
        for(int i = 0; i < n; i++) {
            if(a[i][j] == '-') cnt++;
        }
        if(cnt * 2 > n) cntb++;
    }
    return cnta + cntb;
}

void bkt(int i, int j) {
    if(i == n) {
        ans = max(ans, check());
    } else {
        for(auto x : {'-', '+'}) {
            a[i][j] = x;
            if(j == m-1) bkt(i+1, 0);
            else bkt(i, j+1);
        }
    }
} 

void bkt2(int i, int j) {
    if(ok) return;
    if(i == n) {
        if(check() == ans) {
            ok = 1;
            for(int i = 0; i < n; i++) {
                for(int j = 0; j < m; j++) {
                    cout << a[i][j];
                }
                cout << '\n';
            }
        }
    } else {
        for(auto x : {'-', '+'}) {
            a[i][j] = x;
            if(j == m-1) bkt2(i+1, 0);
            else bkt2(i, j+1);
        }
    }
}

void solve() {
    cin >> n >> m;
    ans = 0;
    ok = 0;
    bkt(0, 0); 
    cout << ans << '\n';
    bkt2(0, 0);
}

int main() {
    int t;
    cin >> t;
    while(t--) solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 4 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2070 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 4 ms 296 KB Output is correct
3 Execution timed out 2070 ms 204 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2088 ms 332 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2040 ms 288 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 4 ms 296 KB Output is correct
3 Execution timed out 2070 ms 204 KB Time limit exceeded
4 Halted 0 ms 0 KB -