Submission #163150

# Submission time Handle Problem Language Result Execution time Memory
163150 2019-11-11T14:34:30 Z abacaba Red-blue table (IZhO19_stones) C++14
100 / 100
173 ms 5368 KB
#include <iostream>
#include <string>
#include <unordered_map>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define y1 abcde
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

const int inf = 2e9;
const int N = 1e3 + 15;
int t, n, m, a[N][N], row[N], col[N];

inline void make_red(int i, int j) {
    a[i][j] = 1, ++row[i], ++col[j];
}

inline void make_blue(int i, int j) {
    a[i][j] = 0, --row[i], --col[j];
}

main() {
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    cin >> t;
    while(t--) {
        int ans = 0;
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= m; ++j)
                a[i][j] = row[i] = col[j] = 0;
        cin >> n >> m;
        if(n <= m) {
            for(int i = 1; i <= n; ++i) {
                vector <pii> pot = {};
                for(int j = 1; j <= m; ++j)
                    if(2 * (col[j] + 1) < n)
                        pot.pb({col[j], j});
                if(pot.size() < m / 2 + 1)
                    break;
                sort(pot.begin(), pot.end());
                for(int j = 0; j <= m / 2; ++j)
                    make_red(i, pot[j].se);
            }
        }
        else {
            for(int i = 1; i <= n; ++i)
                for(int j = 1; j <= m; ++j)
                    make_red(i, j);
            for(int j = 1; j <= m; ++j) {
                vector <pii> pot = {};
                for(int i = 1; i <= n; ++i)
                    if(2 * (row[i] - 1) > m)
                        pot.pb({row[i], i});
                if(pot.size() < n / 2 + 1)
                    break;
                sort(pot.begin(), pot.end(), [&](pii a, pii b) {
                    return a > b;
                });
                for(int i = 0; i <= n / 2; ++i)
                    make_blue(pot[i].se, j);
            }
        }
        for(int i = 1; i <= n; ++i)
            ans += 2 * row[i] > m;
        for(int i = 1; i <= m; ++i)
            ans += 2 * col[i] < n;
        cout << ans << endl;
        for(int i = 1; i <= n; ++i, cout << endl)
            for(int j = 1; j <= m; ++j)
                cout << (a[i][j] ? '+' : '-');
    }
    return 0;
}

Compilation message

stones.cpp:53:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
stones.cpp: In function 'int main()':
stones.cpp:68:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(pot.size() < m / 2 + 1)
                    ~~~~~~~~~~~^~~~~~~~~~~
stones.cpp:84:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if(pot.size() < n / 2 + 1)
                    ~~~~~~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 1840 KB Output is correct
2 Correct 86 ms 4316 KB Output is correct
3 Correct 123 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 116 ms 2052 KB Output is correct
2 Correct 63 ms 4088 KB Output is correct
3 Correct 57 ms 3448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 632 KB Output is correct
4 Correct 4 ms 632 KB Output is correct
5 Correct 79 ms 1840 KB Output is correct
6 Correct 86 ms 4316 KB Output is correct
7 Correct 123 ms 4940 KB Output is correct
8 Correct 116 ms 2052 KB Output is correct
9 Correct 63 ms 4088 KB Output is correct
10 Correct 57 ms 3448 KB Output is correct
11 Correct 18 ms 760 KB Output is correct
12 Correct 116 ms 4472 KB Output is correct
13 Correct 112 ms 4896 KB Output is correct
14 Correct 173 ms 4064 KB Output is correct
15 Correct 77 ms 5368 KB Output is correct
16 Correct 57 ms 4344 KB Output is correct
17 Correct 49 ms 3448 KB Output is correct