Submission #500487

# Submission time Handle Problem Language Result Execution time Memory
500487 2021-12-31T07:32:43 Z IOI_champion_in_1980 Red-blue table (IZhO19_stones) C++14
100 / 100
48 ms 2280 KB
// red blue izho 19
#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);
    }
}

Compilation message

stones.cpp: In function 'void test(int, int)':
stones.cpp:62:13: warning: unused variable 'place' [-Wunused-variable]
   62 |         int place = 0;
      |             ^~~~~
stones.cpp:58:9: warning: variable 'sum' set but not used [-Wunused-but-set-variable]
   58 |     int sum = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 6 ms 332 KB Output is correct
4 Correct 11 ms 388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 1400 KB Output is correct
2 Correct 21 ms 1988 KB Output is correct
3 Correct 19 ms 1980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1348 KB Output is correct
2 Correct 28 ms 1768 KB Output is correct
3 Correct 17 ms 1588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 6 ms 332 KB Output is correct
4 Correct 11 ms 388 KB Output is correct
5 Correct 48 ms 1400 KB Output is correct
6 Correct 21 ms 1988 KB Output is correct
7 Correct 19 ms 1980 KB Output is correct
8 Correct 31 ms 1348 KB Output is correct
9 Correct 28 ms 1768 KB Output is correct
10 Correct 17 ms 1588 KB Output is correct
11 Correct 21 ms 544 KB Output is correct
12 Correct 20 ms 1832 KB Output is correct
13 Correct 23 ms 1988 KB Output is correct
14 Correct 18 ms 1628 KB Output is correct
15 Correct 23 ms 2280 KB Output is correct
16 Correct 16 ms 1880 KB Output is correct
17 Correct 8 ms 1220 KB Output is correct