Submission #159253

# Submission time Handle Problem Language Result Execution time Memory
159253 2019-10-21T16:17:28 Z Dorina_Sapfiria Red-blue table (IZhO19_stones) C++14
100 / 100
48 ms 2288 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#define int long long
#define pb push_back
#define F first
#define S second
#define pii pair<int, int>

using namespace std;

void Solve (int n, int m)
{
    if (n>=m)
    {
        int ans=n;
        bool a [n+1][m+1]{};
        vector <pii> v;
        for (int i=1; i<=n; i++)
        {
            v.pb({0, i});
        }
        int j=1;
        int k=m/2+1;
        k=m-k;
        int h=n/2+1;
//        cout << "(" << k << " " << h << ")\n";
        while (j<=m)
        {
            sort(v.begin(), v.end());
            bool fin=0;
            for (int i=0; i<h; i++)
            {
//                cout << "!" << v[i].S << " " << v[i].F << "\n";
                if (v[i].F+1>k)
                {
                    fin=1;
                    break;
                }
            }
            if (fin)
            {
                break;
            }
            for (int i=0; i<h; i++)
            {
//                cout << "--> " << v[i].S << " " << j << "\n";
                a[v[i].S][j]=1;
                v[i].F++;
            }
            ans++;
            j++;
//            cout << "~~~" << j << "\n";
//            cout << "\n";
        }
        cout << ans << "\n";
        for (int i=1; i<=n; i++)
        {
            for (int j=1; j<=m; j++)
            {
                if(a[i][j]) cout << "-";
                else cout << "+";
            }
            cout << "\n";
        }
        return;
    }
    else
    {
        int ans=m;
        bool a[n+1][m+1]{};
        int k=n/2+1;
        k=n-k;
        int h=m/2+1;
//        cout << "(" << k << " " << h << ")\n";
        int j=1;
        vector <pii> v;
        for (int i=1; i<=m; i++)
        {
            v.pb({0, i});
        }
        while (j<=n)
        {
            sort(v.begin(), v.end());
            bool fin=0;
            for (int i=0; i<h; i++)
            {
                if (v[i].F+1>k)
                {
                    fin=1;
                    break;
                }
            }
            if (fin) break;
            for (int i=0; i<h; i++)
            {
                a[j][v[i].S]=1;
                v[i].F++;
            }
            ans++;
            j++;
        }
        cout << ans << "\n";
        for (int i=1; i<=n; i++)
        {
            for (int j=1; j<=m; j++)
            {
                if (a[i][j]) cout << '+';
                else cout << '-';
            }
            cout << "\n";
        }
        return;
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #else
//    freopen("cheval.in", "r", stdin);
//    freopen("cheval.out", "w", stdout);
    #endif // LOCAL
    int t;
    cin >> t;
    while (t--)
    {
        int n,m;
        cin >> n >> m;
        Solve(n, m);
//        cout << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 256 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 380 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 1312 KB Output is correct
2 Correct 42 ms 1912 KB Output is correct
3 Correct 40 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 1400 KB Output is correct
2 Correct 39 ms 1764 KB Output is correct
3 Correct 36 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 45 ms 1312 KB Output is correct
6 Correct 42 ms 1912 KB Output is correct
7 Correct 40 ms 1912 KB Output is correct
8 Correct 44 ms 1400 KB Output is correct
9 Correct 39 ms 1764 KB Output is correct
10 Correct 36 ms 1400 KB Output is correct
11 Correct 13 ms 624 KB Output is correct
12 Correct 38 ms 1576 KB Output is correct
13 Correct 40 ms 1564 KB Output is correct
14 Correct 30 ms 1144 KB Output is correct
15 Correct 48 ms 2288 KB Output is correct
16 Correct 34 ms 1784 KB Output is correct
17 Correct 18 ms 1016 KB Output is correct