Submission #168772

# Submission time Handle Problem Language Result Execution time Memory
168772 2019-12-16T08:05:56 Z ptreap Red-blue table (IZhO19_stones) C++14
0 / 100
2000 ms 376 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <iomanip>
#include <stdio.h>
#include <ctime>
#include <fstream>
#include <chrono>
#define _GLIBCXX_DEBUG
#define int long long
#define double long double
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)x.size()
#define pb push_back;
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("fast-math")
#pragma GCC optimize "-O3"
typedef int supertype;


using namespace std;


vector <vector <char>> generate(int mask, int n, int m) {
    vector <vector <char>> ans(n, vector <char>(m));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ans[n - i - 1][m - j - 1] = mask >> (1LL * (i * m)) >> (1LL << j) & 1;
        }
    }
    return ans;
}


void solve() {
    int n, m;
    cin >> n >> m;
    int best = 0, bestmask = 0;
    for (int mask = 0; mask < (1LL << (n * m)); mask++) {
        auto now = generate(mask, n, m);
        int a = 0, b = 0;
        for (int i = 0; i < n; i++) {
            int red = 0;
            for (int j = 0; j < m; j++) {
                if (now[i][j])
                    red++;
            }
            if (red > m - red)
                a++;
        }
        for (int j = 0; j < m; j++) {
            int blue = 0;
            for (int i = 0; i < n; i++) {
                if (!now[i][j])
                    blue++;
            }
            if (blue > n - blue)
                b++;
        }
        if (a + b > best) {
            best = a + b;
            bestmask = mask;
        }
    }
    cout << best << endl;
    auto ans = generate(bestmask, n, m);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (ans[i][j])
                cout << '+';
            else
                cout << '-';
        }
        cout << endl;
    }
}


signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(NULL));
    //freopen("sort.in", "r", stdin);
    //freopen("sort.in", "r", stdin);

    int tests = 1;
    cin >> tests;
    while (tests--) {
        solve();
    }

    return 0;
}


/*

*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 29 ms 376 KB Wrong answer in test 2 1: 1 < 2
# Verdict Execution time Memory Grader output
1 Execution timed out 2050 ms 376 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 29 ms 376 KB Wrong answer in test 2 1: 1 < 2
# Verdict Execution time Memory Grader output
1 Execution timed out 2052 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2059 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 29 ms 376 KB Wrong answer in test 2 1: 1 < 2