Submission #487030

# Submission time Handle Problem Language Result Execution time Memory
487030 2021-11-13T20:24:59 Z SirCovidThe19th Red-blue table (IZhO19_stones) C++17
100 / 100
52 ms 5144 KB
#include <bits/stdc++.h>
using namespace std;

void solve(){
    int n, m, flip = 0; cin >> n >> m; 
    if (n < m) swap(n, m), flip = 1;
    int ans[n + 1][m + 1] = {}, rowFill[n + 1] = {}, tot = n + m;

    for (int j = 1, i = 1; j <= m; j++){
        int cnt = 0;
        while (cnt < n - (n / 2 + 1)){
            ans[i][j] = 1; rowFill[i]++;
            i++; cnt++; if (i > n) i = 1;
        }
    }
    for (int j = 1; j <= m; j++){
        int badCol = 0;
        for (int i = 1; i <= n; i++)
            if (rowFill[i] < m / 2 + 1 and !ans[i][j]){
                ans[i][j] = 1; rowFill[i]++;
                badCol = 1;
            }
        tot -= badCol;
    }
    cout<<tot<<endl;
    if (flip) swap(n, m);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++){
            int cur = !flip ? ans[i][j] : !ans[j][i];
            cout<<(cur ? "+" : "-")<<(j == m ? "\n" : "");
        }
}

int main(){
    int tc; cin >> tc;
    while (tc--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 292 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 4 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 1252 KB Output is correct
2 Correct 39 ms 3708 KB Output is correct
3 Correct 37 ms 3960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 1300 KB Output is correct
2 Correct 36 ms 3140 KB Output is correct
3 Correct 32 ms 2324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 292 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 4 ms 300 KB Output is correct
5 Correct 45 ms 1252 KB Output is correct
6 Correct 39 ms 3708 KB Output is correct
7 Correct 37 ms 3960 KB Output is correct
8 Correct 45 ms 1300 KB Output is correct
9 Correct 36 ms 3140 KB Output is correct
10 Correct 32 ms 2324 KB Output is correct
11 Correct 12 ms 488 KB Output is correct
12 Correct 34 ms 2748 KB Output is correct
13 Correct 35 ms 2264 KB Output is correct
14 Correct 32 ms 1532 KB Output is correct
15 Correct 52 ms 5144 KB Output is correct
16 Correct 33 ms 3892 KB Output is correct
17 Correct 15 ms 1840 KB Output is correct