Submission #681404

# Submission time Handle Problem Language Result Execution time Memory
681404 2023-01-13T03:16:33 Z drdilyor Red-blue table (IZhO19_stones) C++17
100 / 100
28 ms 4308 KB
#include <bits/stdc++.h>
#ifdef ONPC
    #include "t_debug.cpp"
#else
    #define debug(...) 42
#endif
using namespace std;
//namespace pbds = __gnu_pbds;
using ll = long long;
const int inf = 1e9;
const ll infl = 1e18;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) { return is >> p.first >> p.second; }
template<typename Cont> int sz(const Cont& cont) { return int(cont.size()); }
const string fileio = "";
constexpr int tests = 1, nmax = 2e5, nlog = __lg(nmax), mod = 1e9+7;

pair<int, vector<string>> construct(int n, int m) {
    vector res(n, string(m, '-'));
    int k = 0, kr = n - (n/2 + 1);
    for (int i = 0; i < n; i++) {
        int cnt = m / 2 + 1;
        while (cnt-- && k / m < kr) {
            res[i][k % m] = '+';
            k++;
        }
    }
    int a = 0, b = 0;
    for (int i = 0; i < n; i++) {
        int ca{}, cb{};
        for (int j = 0; j < m; j++) {
            if (res[i][j] == '+') ca++;
            else cb++;
        }
        a += ca > cb;
    }
    for (int i = 0; i < m; i++) {
        int ca{}, cb{};
        for (int j = 0; j < n; j++) {
            if (res[j][i] == '-') ca++;
            else cb++;
        }
        b += ca > cb;
    }
    return {a + b, res};
}

int solve() {

    int n, m;
    cin >> n >> m;
    if (!cin) return 1;
    auto a = construct(n, m);
    auto b = construct(m, n);
    debug(a.second);
    debug(b.second);
    if (b.first > a.first) {
        a.first = b.first;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                char c = b.second[j][i];
                a.second[i][j] = c == '+' ? '-' : '+';
            }
        }
    }

    cout <<a.first << '\n';
    for (auto r : a.second) {
        cout << r << '\n';
    }

    return 0;
}

signed main() {
    int t = 1;
    #ifdef ONPC
    t = 10000;
    #else
    if (fileio.size()) {freopen((fileio+".in").c_str(),"r",stdin);freopen((fileio+".out").c_str(),"w",stdout);}
    #endif
    cin.tie(0)->sync_with_stdio(0);
    if (tests) cin >> t;
    while (t-- && cin) {
        if (solve()) break;
        #ifdef ONPC
            cout << "____________________" << endl;
        #endif
    }
    return 0;
}

/*
     █████               █████  ███  ████                               
    ▒▒███               ▒▒███  ▒▒▒  ▒▒███                               
  ███████  ████████   ███████  ████  ▒███  █████ ████  ██████  ████████ 
 ███▒▒███ ▒▒███▒▒███ ███▒▒███ ▒▒███  ▒███ ▒▒███ ▒███  ███▒▒███▒▒███▒▒███
▒███ ▒███  ▒███ ▒▒▒ ▒███ ▒███  ▒███  ▒███  ▒███ ▒███ ▒███ ▒███ ▒███ ▒▒▒ 
▒███ ▒███  ▒███     ▒███ ▒███  ▒███  ▒███  ▒███ ▒███ ▒███ ▒███ ▒███     
▒▒████████ █████    ▒▒████████ █████ █████ ▒▒███████ ▒▒██████  █████    
 ▒▒▒▒▒▒▒▒ ▒▒▒▒▒      ▒▒▒▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒   ▒▒▒▒▒███  ▒▒▒▒▒▒  ▒▒▒▒▒     
                                            ███ ▒███                    
                                           ▒▒██████                     
                                            ▒▒▒▒▒▒
*/

Compilation message

stones.cpp: In function 'int solve()':
stones.cpp:5:24: warning: statement has no effect [-Wunused-value]
    5 |     #define debug(...) 42
      |                        ^~
stones.cpp:56:5: note: in expansion of macro 'debug'
   56 |     debug(a.second);
      |     ^~~~~
stones.cpp:5:24: warning: statement has no effect [-Wunused-value]
    5 |     #define debug(...) 42
      |                        ^~
stones.cpp:57:5: note: in expansion of macro 'debug'
   57 |     debug(b.second);
      |     ^~~~~
stones.cpp: In function 'int main()':
stones.cpp:81:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |     if (fileio.size()) {freopen((fileio+".in").c_str(),"r",stdin);freopen((fileio+".out").c_str(),"w",stdout);}
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stones.cpp:81:74: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |     if (fileio.size()) {freopen((fileio+".in").c_str(),"r",stdin);freopen((fileio+".out").c_str(),"w",stdout);}
      |                                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1392 KB Output is correct
2 Correct 17 ms 2992 KB Output is correct
3 Correct 19 ms 3400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1424 KB Output is correct
2 Correct 15 ms 2460 KB Output is correct
3 Correct 13 ms 1988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 28 ms 1392 KB Output is correct
6 Correct 17 ms 2992 KB Output is correct
7 Correct 19 ms 3400 KB Output is correct
8 Correct 18 ms 1424 KB Output is correct
9 Correct 15 ms 2460 KB Output is correct
10 Correct 13 ms 1988 KB Output is correct
11 Correct 7 ms 596 KB Output is correct
12 Correct 17 ms 2368 KB Output is correct
13 Correct 17 ms 1824 KB Output is correct
14 Correct 12 ms 1280 KB Output is correct
15 Correct 23 ms 4308 KB Output is correct
16 Correct 13 ms 3276 KB Output is correct
17 Correct 8 ms 1620 KB Output is correct