Submission #1172541

#TimeUsernameProblemLanguageResultExecution timeMemory
1172541AtabayRajabliRed-blue table (IZhO19_stones)C++20
100 / 100
269 ms9284 KiB
#include <bits/stdc++.h>
#define int long long
#define all(v) v.begin(), v.end()
using namespace std;

const int sz = 1e3 + 1, inf = 1e18;
int n, m, a[sz][sz], ans;

void calc(int n, int m)
{
    if(n >= m) swap(n, m);
    ans = m;
    int mx = m / 2 + 1, nx = (n - 1) / 2, col[m + 1] = {0}, row[n + 1] = {0};
    for(int i = 1; i <= n; )
    {
        bool ok = 0;
        for(int j = 1; j <= m; j++)
        {
            if(col[j] == nx) continue;
            ok |= 1;
            a[i][j] = 1;
            col[j]++;
            row[i]++;
            if(row[i] == mx) 
            {
                ans++;
                i++;
            }
        }
        if(!ok) break;
    }
}

void solve()
{
    cin >> n >> m;
    memset(a, 0, sizeof(a));
    calc(n, m);
    cout << ans << '\n';
    if(n >= m)
    {
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= m; j++)
            {
                cout << (a[j][i] ? '-' : '+');
            }
            cout << '\n';
        }
    }
    else
    {
        for(int i = 1; i <= n; i++)
        {
            for(int j = 1; j <= m; j++)
            {
                cout << (a[i][j] ? '+' : '-');
            }
            cout << '\n';
        }
    }
}

signed main()
{                                                                  
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int t;
    cin >> t;
    while(t--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...