Submission #681548

# Submission time Handle Problem Language Result Execution time Memory
681548 2023-01-13T09:48:34 Z Matteo_Verz Red-blue table (IZhO19_stones) C++17
100 / 100
48 ms 2204 KB
#include <bits/stdc++.h>

using namespace std;

auto solve(int x, int y) {
    char ch, replacech;
    if (x >= y) {
        ch = '+';
        replacech = '-';
    } else {
        ch = '-';
        replacech = '+';
    }

    vector <vector <char>> a(x, vector <char>(y, ch));
    int ans;
    if (x >= y) {
        ans = x;
        vector <int> freq(x);
        int pos = 0, col = 0;
        while (true) {
            if (freq[(pos + x / 2) % x] < (y - 1) / 2) {
                for (int i = pos; i <= pos + x / 2; i++) {
                    freq[i % x]++;
                    a[i % x][col] = replacech;
                }
                pos = (pos + x / 2 + 1) % x;
            } else break;
            col++;
            ans++;
        }
    } else {
        ans = y;
        vector <int> freq(y);
        int pos = 0, line = 0;
        while (true) {
            if (freq[(pos + y / 2) % y] < (x - 1) / 2) {
                for (int i = pos; i <= pos + y / 2; i++) {
                    freq[i % y]++;
                    a[line][i % y] = replacech;
                }
                pos = (pos + y / 2 + 1) % y;
            } else break;
            line++;
            ans++;
        }
    }

    cout << ans << '\n';
    return a;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        int x, y;
        cin >> x >> y;
        auto a = solve(x, y);

        for (int i = 0; i < x; i++, cout << '\n')
            for (int j = 0; j < y; j++)
                cout << a[i][j];
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 1292 KB Output is correct
2 Correct 32 ms 1760 KB Output is correct
3 Correct 36 ms 1868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 1256 KB Output is correct
2 Correct 29 ms 1436 KB Output is correct
3 Correct 25 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
5 Correct 36 ms 1292 KB Output is correct
6 Correct 32 ms 1760 KB Output is correct
7 Correct 36 ms 1868 KB Output is correct
8 Correct 48 ms 1256 KB Output is correct
9 Correct 29 ms 1436 KB Output is correct
10 Correct 25 ms 1364 KB Output is correct
11 Correct 10 ms 536 KB Output is correct
12 Correct 34 ms 1464 KB Output is correct
13 Correct 31 ms 1396 KB Output is correct
14 Correct 21 ms 1104 KB Output is correct
15 Correct 33 ms 2204 KB Output is correct
16 Correct 23 ms 1752 KB Output is correct
17 Correct 11 ms 852 KB Output is correct