제출 #498911

#제출 시각아이디문제언어결과실행 시간메모리
498911NachoLibreRed-blue table (IZhO19_stones)C++17
100 / 100
38 ms3240 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() using namespace std; void print(vector<vector<char> > &c) { for(int i = 0; i < sz(c); ++i) { for(int j = 0; j < sz(c[0]); ++j) { cout << c[i][j]; } cout << "\n"; } } vector<vector<char>> perfect(int n, int m, int x, int y) { vector<vector<char> > c(n, vector<char>(m, '-')); int k = 0; for(int i = 0; i < n; ++i) { for(int j = 0; j < y; ++j) { c[i][k] = '+'; k = (k + 1) % m; } } return c; } int main() { ios::sync_with_stdio(0); cin.tie(0); int t; cin >> t; for(int ti = 1; ti <= t; ++ti) { int n, m; cin >> n >> m; int forsaken = 1e7; int fn = 0, fm = 0; int fx = 0, fy = 0; for(int i = 0; i <= n; ++i) { for(int j = 0; j <= m; ++j) { int ns = n - i; int ms = m - j; int x = max(0, n / 2 + 1 - i); int y = max(0, m / 2 + 1 - j); if(x * ms + y * ns <= ns * ms) { if(i + j < forsaken) { forsaken = i + j; fn = ns; fm = ms; fx = x; fy = y; } } } } vector<vector<char> > c = perfect(fn, fm, fx, fy); for(int i = 0; i < fn; ++i) { for(int j = fm; j < m; ++j) { c[i].push_back('+'); } } for(int i = fn; i < n; ++i) { c.push_back(vector<char>(m, '-')); } cout << n + m - forsaken << "\n"; print(c); } 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...