Submission #147759

# Submission time Handle Problem Language Result Execution time Memory
147759 2019-08-30T15:06:56 Z leatherman Red-blue table (IZhO19_stones) C++14
43 / 100
44 ms 2776 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#define ll long long
#define ld long double
#define endl "\n"
#define fi first
#define se second
#define y1 sadjfskldf
#define PB push_back
#define sqr(x) ((x) * (x))
#define all(x) x.begin(), x.end()
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());

const ll N = 1005;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll Q,n,m,a[N][N],b[N][N],ans;
void check()
{
    ll l,r,kol = 0;
    for(int i = 1; i <= n; i++)
    {
        l = 0;
        for(int j = 1; j <= m; j++) l += a[i][j];
        r = m - l;
        if(l > r) kol++;
    }
    for(int j = 1; j <= m; j++)
    {
        l = 0;
        for(int i = 1; i <= n; i++) l += a[i][j];
        r = n - l;
        if(r > l) kol++;
    }
    if(kol > ans)
    {
        ans = kol;
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++) b[i][j] = a[i][j];
    }
}
void solv_1()
{
    ll x,y;
    x = m / 2;
    y = m - x;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
        {
            if(j <= x || i % y + (i % y == 0) * y == j - x) a[i][j] = 1;
            else a[i][j] = 0;
        }
    check();
}
void solv_2()
{
    ll x,y;
    x = n / 2;
    y = n - x;
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
        {
            if(i <= x || j % y + (j % y == 0) * y == i - x) a[i][j] = 0;
            else a[i][j] = 1;
        }
    check();
}
void solv_3()
{
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
        {
            if(j <= m / 2 + 1) a[i][j] = 1;
            else a[i][j] = 0;
        }
    check();
}
void solv_4()
{
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++)
        {
            if(i <= n / 2 + 1) a[i][j] = 0;
            else a[i][j] = 1;
        }
    check();
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>Q;
//    Q = 1;
    while(Q--)
    {
        cin>>n>>m;
        ans = 0;
        solv_1();
        solv_2();
        solv_3();
        solv_4();
        cout<<ans<<endl;
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= m; j++) cout<<(b[i][j] ? '+' : '-');
            cout<<endl;
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 760 KB Output is correct
4 Correct 5 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 2340 KB Wrong answer in test 97 21: 108 < 116
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 2776 KB Wrong answer in test 24 24: 36 < 44
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 760 KB Output is correct
4 Correct 5 ms 760 KB Output is correct
5 Incorrect 44 ms 2340 KB Wrong answer in test 97 21: 108 < 116
6 Halted 0 ms 0 KB -