Submission #494861

# Submission time Handle Problem Language Result Execution time Memory
494861 2021-12-16T21:05:24 Z Amer Red-blue table (IZhO19_stones) C++14
100 / 100
49 ms 2292 KB
#include <iostream>

using namespace std;

const int maxN = 1005;

bool marked[maxN][maxN];

int num[maxN];

int solve(int n, int m)
{
    int midN = n / 2 + 1;
    int midM = (m - 1) / 2;

    for (int i = 0; i <= n + 1; i++)
    {
        for (int j = 0; j <= n + 1; j++)
        {
            marked[i][j] = 0;
        }
    }

    for (int i = 0; i <= n + 1; i++)
    {
        num[i] = 0;
    }

    int sum = n;

    int pointer = 1;

    for (int i = 1; i <= m; i++)
    {
        int steps;

        bool full = false;

        for (steps = 1; steps <= midN; steps++)
        {
            if (num[pointer] >= midM)
            {
                full = true;
                break;
            }

            marked[i][pointer] = true;
            num[pointer]++;

            pointer++;

            if (pointer > n)
            {
                pointer = 1;
            }
        }

        if (steps >= midN + 1)
        {
            sum++;
        }

        if(full)
        {
            break;
        }
    }

    cout << sum << endl;

    return 0;
}

void test(int n, int m)
{
    int sum = 0;

    if (n > m)
    {
        sum = solve(n, m);

        int place = 0;

        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                if (marked[j][i])
                {
                    cout << "-";
                }
                else
                {
                    cout << "+";
                }
            }

            cout << endl;
        }
    }
    else
    {
        sum = solve(m, n);
        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <= m; j++)
            {
                if (marked[i][j])
                {
                    cout << "+";
                }
                else
                {
                    cout << "-";
                }
            }

            cout << endl;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;

    for (int i = 0; i < t; i++)
    {
        int n, m;

        cin >> n >> m;
        test(n, m);
    }
    return 0;
}

/*
3
5 6
9 10
3 10
*/

Compilation message

stones.cpp: In function 'void test(int, int)':
stones.cpp:82:13: warning: unused variable 'place' [-Wunused-variable]
   82 |         int place = 0;
      |             ^~~~~
stones.cpp:76:9: warning: variable 'sum' set but not used [-Wunused-but-set-variable]
   76 |     int sum = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 7 ms 332 KB Output is correct
4 Correct 11 ms 400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 1356 KB Output is correct
2 Correct 21 ms 1992 KB Output is correct
3 Correct 23 ms 1992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 1344 KB Output is correct
2 Correct 24 ms 1832 KB Output is correct
3 Correct 19 ms 1584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 7 ms 332 KB Output is correct
4 Correct 11 ms 400 KB Output is correct
5 Correct 49 ms 1356 KB Output is correct
6 Correct 21 ms 1992 KB Output is correct
7 Correct 23 ms 1992 KB Output is correct
8 Correct 35 ms 1344 KB Output is correct
9 Correct 24 ms 1832 KB Output is correct
10 Correct 19 ms 1584 KB Output is correct
11 Correct 24 ms 592 KB Output is correct
12 Correct 23 ms 1872 KB Output is correct
13 Correct 31 ms 2028 KB Output is correct
14 Correct 17 ms 1672 KB Output is correct
15 Correct 22 ms 2292 KB Output is correct
16 Correct 17 ms 1880 KB Output is correct
17 Correct 13 ms 1272 KB Output is correct