Submission #1246002

#TimeUsernameProblemLanguageResultExecution timeMemory
1246002tschav_Red-blue table (IZhO19_stones)C++20
0 / 100
13 ms1352 KiB
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int N, M; cin >> N >> M; // 1) compute the maximum int best; if (N == 1 || M == 1) { best = max(N, M); } else { best = N + M - 2; } cout << best << "\n"; // 2) build the grid // Case: single row if (N == 1) { // To maximize B, make every cell '-' // (each of the M columns has 1 blue > 0 red) cout << string(M, '-') << "\n"; continue; } // Case: single column if (M == 1) { // To maximize A, make every cell '+' // (each of the N rows has 1 red > 0 blue) for (int i = 0; i < N; i++) cout << "+\n"; continue; } // General N,M >= 2: // • We “sacrifice” row 0 by filling it all with '-' → it has no red-majority. // • We “sacrifice” column M-1 by filling it all with '+' → it has no blue-majority. // • Every other row has exactly one '-' (in col M-1) and M-1 '+' → red-majority. // • Every other column has exactly one '+' (in row 0) and N-1 '-' → blue-majority. // // Thus A = N-1, B = M-1, A+B = N+M-2. for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (i == 0) { // sacrificed row → all blues cout << '-'; } else if (j == M-1) { // sacrificed column → all reds cout << '+'; } else { // interior → give red to help rows cout << '+'; } } cout << "\n"; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...