Submission #1085027

#TimeUsernameProblemLanguageResultExecution timeMemory
1085027makravRed-blue table (IZhO19_stones)C++14
100 / 100
23 ms2416 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define pb push_back #define ff first #define sc second void solve() { int n, m; cin >> n >> m; if (n == 1) { cout << m << '\n'; for (int i = 0; i < m; i++) cout << '-'; cout << '\n'; return; } if (m == 1) { cout << n << '\n'; for (int i = 0; i < n; i++) { cout << "+\n"; } return; } pair<int, int> b = {0, 0}; for (int r = 0; r <= n; r++) { for (int c = 0; c <= m; c++) { int needr = max(0, m / 2 + 1 - (m - c)), needc = max(0, n / 2 + 1 - (n - r)); if (needc * c + needr * r <= r * c) { if (b.first + b.second < r + c) { b = {r, c}; } } } } cout << b.first + b.second << '\n'; vector<vector<char>> ans(n, vector<char>(m, '+')); for (int j = b.second; j < m; j++) { for (int i = 0; i < n; i++) ans[i][j] = '+'; } for (int i = b.first; i < n; i++) { for (int j = 0; j < b.second; j++) ans[i][j] = '-'; } int r = b.first, c = b.second; int needr = max(0, m / 2 + 1 - (m - c)), needc = max(0, n / 2 + 1 - (n - r)); int cur = 0; for (int i = 0; i < r; i++) { for (int j = 0; j < c - needr; j++) { ans[i][cur] = '-'; cur = (cur + 1) % c; } } for (auto &u : ans) { for (auto v : u) cout << v; cout << '\n'; } } signed main() { int tt = 1; #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #else ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #endif cin >> tt; while (tt--) { solve(); } return 0; }

Compilation message (stderr)

stones.cpp: In function 'void solve()':
stones.cpp:47:46: warning: unused variable 'needc' [-Wunused-variable]
   47 |     int needr = max(0, m / 2 + 1 - (m - c)), needc = max(0, n / 2 + 1 - (n - r));
      |                                              ^~~~~
#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...