Submission #161909

# Submission time Handle Problem Language Result Execution time Memory
161909 2019-11-05T09:39:11 Z Alexa2001 Red-blue table (IZhO19_stones) C++17
100 / 100
10 ms 3448 KB
#include <bits/stdc++.h>

using namespace std;

const int Nmax = 1005;

bool marked[Nmax][Nmax];
char ans[Nmax][Nmax];
int cnt[Nmax];
int my_ans;

void prec(int n, int m)
{
    int i, j;

    for(i=1; i<=n; ++i)
        for(j=1; j<=m; ++j)
            marked[i][j] = 0, cnt[j] = 0;

    int nc, mc;
    mc = m / 2 + 1;
    nc = (n-1)/2;

    int start = 1, step;

    my_ans = m;

    for(i=1; i<=n; ++i)
    {
        for(step = 1; step <= mc; ++step)
        {
            if(cnt[start] == nc) break;
            ++cnt[start];
            marked[i][start] = 1;
          
            ++start;
            if(start == m+1) start = 1;
        }
        
        if(step == mc + 1) ++my_ans;
    }
}

void solve()
{
    int n, m;
    cin >> n >> m;

    if(n > m) prec(m, n);
        else prec(n, m);

    int i, j;

    if(n <= m)
    {
        for(i=1; i<=n; ++i)
            for(j=1; j<=m; ++j)
                ans[i][j] = (marked[i][j] ? '+' : '-');
    }
    else 
    {
        for(i=1; i<=n; ++i)
            for(j=1; j<=m; ++j)
                ans[i][j] = (marked[j][i] ? '-' : '+');
    }

    cout << my_ans << '\n';

    for(i=1; i<=n; ++i) 
    {
        ans[i][m+1] = 0;
        cout << (ans[i] + 1) << '\n';
    }
}

int main()
{
   // freopen("input", "r", stdin);
    cin.sync_with_stdio(false); cin.tie(0);

    int tests;
    cin >> tests;
    while(tests--)
        solve();

    return 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 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 1656 KB Output is correct
2 Correct 8 ms 2680 KB Output is correct
3 Correct 7 ms 2936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1656 KB Output is correct
2 Correct 7 ms 2552 KB Output is correct
3 Correct 8 ms 2296 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 3 ms 504 KB Output is correct
5 Correct 10 ms 1656 KB Output is correct
6 Correct 8 ms 2680 KB Output is correct
7 Correct 7 ms 2936 KB Output is correct
8 Correct 8 ms 1656 KB Output is correct
9 Correct 7 ms 2552 KB Output is correct
10 Correct 8 ms 2296 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 7 ms 2424 KB Output is correct
13 Correct 8 ms 2552 KB Output is correct
14 Correct 6 ms 2168 KB Output is correct
15 Correct 9 ms 3448 KB Output is correct
16 Correct 8 ms 2680 KB Output is correct
17 Correct 4 ms 1784 KB Output is correct