Submission #343942

#TimeUsernameProblemLanguageResultExecution timeMemory
343942_aniRed-blue table (IZhO19_stones)C++17
100 / 100
50 ms2284 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; char w[1002][1002]; void Nvnvik(int n, int m, int k) { int i = 0, j = 0; while (i < m) { int cnt = 0; while (cnt < k) { w[j][i] = '-'; j++; if (j >= n) j = 0; cnt++; } i++; } for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (w[i][j] == '.') w[i][j] = '+'; } void Nvnvik2(int n, int m, int k) { int i = 0, j = 0; while (i < m) { int cnt = 0; while (cnt < k) { w[i][j] = '+'; j++; if (j >= m) j = 0; cnt++; } i++; } for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (w[i][j] == '.') w[i][j] = '-'; } int main() { int t; cin >> t; while (t--) { int n, m; cin >> n >> m; if (min(n, m) <= 2) {//checked cout << max(m, n) << '\n'; char d; if (m > n) d = '-'; else d = '+'; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cout << d; cout << '\n'; } continue; } for (int i = 0; i <= n; i++) for (int j = 0; j < m; j++) w[i][j] = '.'; if (n % 2 && m % 2) {//checked cout << n + m - 2 << '\n'; Nvnvik(n - 1, m - 1, n / 2); for (int j = 0; j < m; j++) w[n - 1][j] = '-'; for (int i = 0; i < n - 1; i++) w[i][m - 1] = '+'; } if (n % 2 == 0 && m % 2 == 1) { if (m - 1 - n / 2 <= 1) {//checked cout << n + m - 2 << '\n'; Nvnvik(n, m - 2, n / 2 + 1); for (int i = 0; i < n; i++) w[i][m - 1] = w[i][m - 2] = '+'; } else {//checked cout << n + m - 3 << '\n'; Nvnvik(n - 2, m - 1, n / 2 - 1); for (int j = 0; j < m; j++) { w[n - 1][j] = '-'; w[n - 2][j] = '-'; } for (int i = 0; i < n; i++) { w[i][m - 1] = ('+'); } } } if (n % 2 == 1 && m % 2 == 0) { if (n - 1 - m / 2 <= 1) {//checked cout << n + m - 2 << '\n'; Nvnvik(n - 2, m, n / 2 - 1); for (int i = 0; i < m; i++) w[n - 1][i] = w[n - 2][i] = '-'; } else {//checked cout << n + m - 3 << '\n'; Nvnvik(n - 1, m - 2, n / 2); for (int j = 0; j < m; j++) { w[n - 1][j] = '-'; } for (int i = 0; i < n; i++) { w[i][m - 1] = '+'; w[i][m - 2] = '+'; } } } if (n % 2 == 0 && m % 2 == 0) {//checked if (n - 3 <= m / 2) { cout << n + m - 3 << '\n'; Nvnvik(n - 3, m, n / 2 - 2); for (int i = 0; i < m; i++) w[n - 1][i] = w[n - 2][i] = w[n - 3][i] = '-'; } else if (m - 3 <= n / 2) {//checked cout << n + m - 3 << '\n'; Nvnvik(n, m - 3, n / 2 + 1); for (int i = 0; i < n; i++) w[i][m - 1] = w[i][m - 2] = w[i][m - 3] = '+'; } else {//checked cout << n + m - 4 << '\n'; Nvnvik(n - 2, m - 2, n / 2 - 1); for (int i = 0; i < m; i++) w[n - 1][i] = w[n - 2][i] = '-'; for (int i = 0; i < n - 2; i++) w[i][m - 1] = w[i][m - 2] = '+'; } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cout << w[i][j]; 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...