Submission #681551

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

using namespace std;

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

    vector <vector <char>> a(x, vector <char>(y, ch));
    int 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++;
    }

    if (replacech == '-') { // have been swapped
        vector <vector <char>> b(y, vector <char>(x));
        for (int i = 0; i < x; i++)
            for (int j = 0; j < y; j++)
                b[j][i] = a[i][j];
        a = b;
    }
    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 38 ms 1288 KB Output is correct
2 Correct 43 ms 1852 KB Output is correct
3 Correct 34 ms 3312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 1360 KB Output is correct
2 Correct 31 ms 1708 KB Output is correct
3 Correct 30 ms 1428 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 38 ms 1288 KB Output is correct
6 Correct 43 ms 1852 KB Output is correct
7 Correct 34 ms 3312 KB Output is correct
8 Correct 37 ms 1360 KB Output is correct
9 Correct 31 ms 1708 KB Output is correct
10 Correct 30 ms 1428 KB Output is correct
11 Correct 16 ms 564 KB Output is correct
12 Correct 35 ms 2312 KB Output is correct
13 Correct 30 ms 1848 KB Output is correct
14 Correct 21 ms 1192 KB Output is correct
15 Correct 37 ms 2416 KB Output is correct
16 Correct 27 ms 1740 KB Output is correct
17 Correct 14 ms 1584 KB Output is correct