Submission #159251

# Submission time Handle Problem Language Result Execution time Memory
159251 2019-10-21T16:12:54 Z Dorina_Sapfiria Red-blue table (IZhO19_stones) C++14
0 / 100
46 ms 1400 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=n-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=m-k;
        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());
            int h=m/2+1;
            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 Incorrect 2 ms 256 KB in the table A+B is not equal to 4
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 376 KB in the table A+B is not equal to 48
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB in the table A+B is not equal to 4
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 1344 KB in the table A+B is not equal to 118
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 1400 KB Wrong answer in test 24 24: 42 < 44
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB in the table A+B is not equal to 4
2 Halted 0 ms 0 KB -