Submission #154530

# Submission time Handle Problem Language Result Execution time Memory
154530 2019-09-22T14:08:36 Z hentai_lover Red-blue table (IZhO19_stones) C++14
100 / 100
106 ms 6516 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define lft(x) x * 2
#define rgt(x) x * 2 + 1

#define tm hui_pizda
#define ft first
#define sd second
#define pb push_back
#define pf push_front
#define sz size()
#define cnt continue
#define m_p make_pair
#define fr(i, l, r) for(int i = l; i <= r; ++ i)
#define rf(i, r, l) for(int i = r; i >= l; -- i)
#pragma GCC optimize(-O3)
#pragma GCC optimize(Ofast)
#pragma GCC optimize("unroll-loops")

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using _set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;

typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <pii> vpi;
typedef vector <pll> vpl;

mt19937_64 rnd(time(NULL));

const ll N = 1e6 + 10;
const ll mtrxN = 10;
const ll oo = 1e18 + 10;
//const ll oo = 228;
const ll B = 500;
const ll mod = 1e9 + 7;

struct mtrx{
    ll m[mtrxN][mtrxN] = {};
};
mtrx mtrx_mult(mtrx a, mtrx b){
    mtrx c;
    fr(i, 0, mtrxN - 1){
        fr(j, 0, mtrxN - 1){
            ll sum = 0;
            fr(x, 0, mtrxN - 1){
                sum += a.m[i][x] * b.m[x][j];
                sum %= mod;
            }
            c.m[i][j] = sum;
        }
    }
    return c;
}
mtrx mtrx_pow(mtrx a, ll n){
    mtrx res;
    fr(i, 0, mtrxN - 1)fr(j, 0, mtrxN - 1)res.m[i][j] = a.m[i][j];
    n --;
    while(n){
        if(n&1)res = mtrx_mult(res, a);
        a = mtrx_mult(a, a);
        n >>= 1;
    }
    return res;
}
ll _pow(ll a, ll n){
    ll r = 1;
    while(n){
        if(n&1)r = r * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return r;
}
ll div(ll x, ll y, ll md){
    return x * _pow(y, md - 2) % md;
}

char a[1010][1010];
ll r[1010];

int main(){
    ll T;
    cin >> T;
    while(T --){
        ll n, m, best_ans = -1, p = 0;
        cin >> n >> m;
        bool flag = 0;
        if(n > m)swap(n, m), flag = 1;
        ll gn = n / 2 + 1;
        ll gm = m / 2 + 1;

        ll now_ans = m;
        best_ans = m;
        vector < vector <ll> > upd;
        upd.resize(n + 1);

        vpl v;
        vl r(m + 1, 0);
        fr(i, 1, n)fr(j, 1, m)a[i][j] = '-', r[j] ++;
        fr(i, 1, m)v.pb({r[i], i});

        fr(i, 1, n){
            sort(v.begin(), v.end());
            reverse(v.begin(), v.end());
            ll timer = 0;
            for(auto &j : v){
                timer ++;
                //cout << j.ft << ' ' << j.sd << ' ' << timer << endl;
                if(timer > gm)break;
                //cout << "true" << endl;
                r[j.sd] --;
                if(r[j.sd] < gn)now_ans --;
                upd[i].pb(j.sd);
                j.ft --;
            }
            now_ans ++;
            if(best_ans < now_ans)best_ans = now_ans, p = i;
        }
        fr(i, 1, p)for(auto j : upd[i])a[i][j] = '+';
        cout << best_ans << "\n";
        if(flag){
            fr(i, 1, m){
                fr(j, 1, n)if(a[j][i] == '-')cout << '+';else cout << '-';
                cout << "\n";
            }
        }   else {
            fr(i, 1, n){
                fr(j, 1, m)cout << a[i][j];
                cout << "\n";
            }
        }
    }

    return 0;
}
/*
строки +
столбцы -
*/

Compilation message

stones.cpp:17:22: warning: '#pragma GCC optimize' is not a string or number [-Wpragmas]
 #pragma GCC optimize(-O3)
                      ^
stones.cpp:18:22: warning: '#pragma GCC optimize' is not a string or number [-Wpragmas]
 #pragma GCC optimize(Ofast)
                      ^~~~~
# 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 5 ms 376 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 5 ms 376 KB Output is correct
4 Correct 8 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 1508 KB Output is correct
2 Correct 92 ms 4728 KB Output is correct
3 Correct 88 ms 5076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 1640 KB Output is correct
2 Correct 84 ms 4584 KB Output is correct
3 Correct 77 ms 3824 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 5 ms 376 KB Output is correct
4 Correct 8 ms 376 KB Output is correct
5 Correct 89 ms 1508 KB Output is correct
6 Correct 92 ms 4728 KB Output is correct
7 Correct 88 ms 5076 KB Output is correct
8 Correct 86 ms 1640 KB Output is correct
9 Correct 84 ms 4584 KB Output is correct
10 Correct 77 ms 3824 KB Output is correct
11 Correct 24 ms 544 KB Output is correct
12 Correct 83 ms 3928 KB Output is correct
13 Correct 86 ms 3436 KB Output is correct
14 Correct 63 ms 2128 KB Output is correct
15 Correct 106 ms 6516 KB Output is correct
16 Correct 77 ms 5128 KB Output is correct
17 Correct 35 ms 3036 KB Output is correct