Submission #502606

# Submission time Handle Problem Language Result Execution time Memory
502606 2022-01-06T10:32:06 Z stanislavpolyn Red-blue table (IZhO19_stones) C++17
27 / 100
30 ms 1444 KB
#include <bits/stdc++.h>

#define fr(i, a, b) for(int i = (a); i <= (b); ++i)
#define rf(i, a, b) for(int i = (a); i >= (b); --i)
#define fe(x, y) for(auto& x : y)

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pw(x) (1LL << (x))

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

template<typename T>
bool umn(T& a, T b) { return (a > b ? (a = b, 1) : 0); }
template<typename T>
bool umx(T& a, T b) { return (a < b ? (a = b, 1) : 0); }

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<typename T>
using ve = vector<T>;

const int N = 1e3 + 5;

int n, m;
char a[N][N];
int cntR[N];
int cntB[N];

int solve(int n, int m) {
    fr(i, 1, n) cntR[i] = 0;
    fr(i, 1, m) cntB[i] = 0;

    int needR = m / 2 + 1;
    int needB = n / 2 + 1;

    fr(i, 1, n) {
        fr(j, 1, m) {
            if(cntR[i] < needR && cntB[j] + (n - i) >= needB) {
                cntR[i]++;
                a[i][j] = 'R';
            } else {
                a[i][j] = 'B';
                cntB[j]++;
            }
        }
    }

    int score = 0;
    fr(i, 1, n) score += cntR[i] >= needR;
    fr(i, 1, m) score += cntB[i] >= needB;

    return score;
}

void solve() {
    cin >> n >> m;

    int score1 = 0;
    int score2 = 0;
    score1 = solve(n, m);
    score2 = solve(m, n);

    if(score1 > score2) {
        cout << solve(n, m) << "\n";
        fr(i, 1, n) {
            fr(j, 1, m) {
                cout << (a[i][j] == 'R' ? '+' : '-');
            }
            cout << "\n";
        }
        return;
    }

    cout << solve(m, n) << "\n";
    fr(i, 1, n) {
        fr(j, 1, m) {
            cout << (a[j][i] == 'R' ? '-' : '+');
        }
        cout << "\n";
    }
}

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
#else
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif

    int t;
    cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 2 ms 332 KB Wrong answer in test 5 29: 31 < 32
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 1444 KB Wrong answer in test 97 21: 107 < 116
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 1376 KB Wrong answer in test 24 24: 35 < 44
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Incorrect 2 ms 332 KB Wrong answer in test 5 29: 31 < 32