Submission #162933

# Submission time Handle Problem Language Result Execution time Memory
162933 2019-11-10T10:17:03 Z dandrozavr Red-blue table (IZhO19_stones) C++14
100 / 100
86 ms 3320 KB
/*
Uruchamiamy samolot zwiadowczy ( + 500% do wzlamaniej )

/▄/  /█/  /◐/   /▐/   /▌/ /▀/ /░/ /🔥/   choose  own style!

***IT'S OUR LONG WAY TO THE OIILLLL***


░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░███░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░█▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▀██████████████████████████████████████████████████
░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▄████▄████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ █████
░░░░░░░░░░░░░░░░░░░░░░░░░░░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█████████▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████░░░░░░░░░░░░░░░
*/



//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define ll long long
#define ld long double
#define mp make_pair
#define fi first
#define se second
//#define pi 3.14159265358979323846
#define pii pair < ll , int >
#define pipii pair< int, pair < int , int > >
#define siz(n) (int)(n.size())

const int inf=1e9 + 7;
const ll inf18=1e18 + 7;
const int N=1e3 + 7;

char a[N][N];

int calc(int n, int m)
{
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        int sum = 0;
        for (int j = 0; j < m; ++j)
            if (a[i][j] == '+') ++sum; else --sum;
        if (sum > 0) ++ans;
    }
    for (int j = 0; j < m; ++j)
    {
        int sum = 0;
        for (int i = 0; i < n; ++i)
            if (a[i][j] == '-') ++sum; else --sum;
        if (sum > 0) ++ans;
    }
    return ans;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifdef Estb_probitie
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int t;
    cin >> t;
    while(t--)
    {
        int n, m;
        cin >> n >> m;

        for (int i = 0; i < n; ++i)
            fill(a[i], a[i] + m, '+');
        char b[n][m];

        if (n == 1)
        {
            for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j)
                b[i][j] = '-';
            cout << m << '\n';
        }  else
        if (m <= 2)
        {
            for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j)
                b[i][j] = '+';
            cout << n << '\n';
        } else
        if (n == 2)
        {
            for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j)
                b[i][j] = '-';
            cout << m << '\n';
        } else
        {
            int otv = -1;
            for (int len = 0; len <= min(n - 1, 10); ++len)
            {
                int can = m / 2 - (m % 2 == 0);
                int ccan = can;
                int need = n / 2 + 1 - len;
                int pr = 0;
                for (int i = len; i < n; ++i)
                    fill(a[i], a[i] + m, '+');
                int now = 0;
                if (need)
                for (int iter = 0; iter < can; ++iter)
                {
                    for (int i = len; i < n; ++i)
                    {
                        --need;
                        a[i][now] = '-';
                        if (!need)
                        {
                            need = n / 2 + 1 - len;
                            ++now;
                        }
                    }
                }

                int ans = calc(n, m);
//                for (int i = 0; i< n; ++i)
//                {
//                    for (int j = 0; j < m; ++j)
//                        cout<<a[i][j]<<" ";
//                    cout<<endl;
//                }
//                cout<<endl;

                if (ans > otv)
                {
                    otv = ans;
                    for (int i = 0; i < n; ++i)
                    for (int j = 0; j < m; ++j)
                        b[i][j] = a[i][j];
                }
                for (int j = 0; j < m; ++j)
                    a[len][j] = '-';
            }
            cout << otv << '\n';
        }
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < m; ++j)
            {
                cout<<b[i][j];
            }
            cout << '\n';
        }
    }




}

Compilation message

stones.cpp: In function 'int main()':
stones.cpp:120:21: warning: unused variable 'ccan' [-Wunused-variable]
                 int ccan = can;
                     ^~~~
stones.cpp:122:21: warning: unused variable 'pr' [-Wunused-variable]
                 int pr = 0;
                     ^~
# 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 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 3 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 1440 KB Output is correct
2 Correct 66 ms 2680 KB Output is correct
3 Correct 62 ms 2808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 1536 KB Output is correct
2 Correct 61 ms 2396 KB Output is correct
3 Correct 57 ms 1912 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 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 82 ms 1440 KB Output is correct
6 Correct 66 ms 2680 KB Output is correct
7 Correct 62 ms 2808 KB Output is correct
8 Correct 86 ms 1536 KB Output is correct
9 Correct 61 ms 2396 KB Output is correct
10 Correct 57 ms 1912 KB Output is correct
11 Correct 49 ms 632 KB Output is correct
12 Correct 57 ms 2320 KB Output is correct
13 Correct 65 ms 2424 KB Output is correct
14 Correct 46 ms 1912 KB Output is correct
15 Correct 71 ms 3320 KB Output is correct
16 Correct 53 ms 2552 KB Output is correct
17 Correct 26 ms 1656 KB Output is correct