Submission #308782

#TimeUsernameProblemLanguageResultExecution timeMemory
308782nikatamlianiRed-blue table (IZhO19_stones)C++14
100 / 100
60 ms2304 KiB
#include <bits/stdc++.h>
using namespace std;
int main() {
    int T = 1;
    cin >> T;
    while(T--) {
        int n, m;
        cin >> n >> m;
        bool swapped = 0;
        if(n < m) {
            swap(n, m);
            swapped = true; 
        }
        bool ans[n + 1][m + 1];
        memset(ans, 0, sizeof ans);
        int rows = n, columns = 0, need = m / 2 + 1, to = 0;
        for(int i = 1; i <= m; ++i) {
            int allPlus = min(need, m - i); 
            int rem = m - allPlus, can = n - n / 2 - 1;
            if(allPlus + i * can / rows >= need) {
                columns = i;
                to = allPlus;
            }
        }
        int prev = to + 1;
        for(int i = 1; i <= n; ++i) {
            for(int j = 1; j <= to; ++j) {
                ans[i][j] = 1; 
            }
            int rem = need - to; 
            auto next = [&](int index) {
                return 1 + (index == m ? to : index);
            };
            for(int j = prev; rem--; j = next(j)) {
                prev = next(j);
                ans[i][j] = 1;
            }
        }
        cout << rows + columns << '\n';
        if(!swapped) {
            for(int i = 1; i <= n; ++i) {
                for(int j = 1; j <= m; ++j) {
                    cout << (ans[i][j] ? '+' : '-'); 
                }
                cout << '\n';
            }
        } else {
            for(int i = 1; i <= m; ++i) {
                for(int j = 1; j <= n; ++j) {
                    cout << (ans[j][i] ? '-' : '+');
                }
                cout << '\n';
            }
        }
    }
}

Compilation message (stderr)

stones.cpp: In function 'int main()':
stones.cpp:19:17: warning: unused variable 'rem' [-Wunused-variable]
   19 |             int rem = m - allPlus, can = n - n / 2 - 1;
      |                 ^~~
#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...