#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define ld long double
#define ull unsigned long long
#define ui unsigned int
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define pil pair<int, ll>
#define plli pair<long long, int>
#define pdi pair<double, int>
#define pldldi pair<ld, pair<ld, int>>
#define pdd pair<double, double>
#define pid pair<int, double>
#define piii pair<int, pair<int, int>>
#define pllll pair<long long, long long>
#define pllllll pair<ll, pllll>
#define INF 2e9 + 5
#define size(v) v.size()
#define f first
#define s second
#define Pi 3.14159265359
using namespace std;
void Subtask4(int n, int m){
vector<vector<char>>grid(n + 1, vector<char>(m + 1, '+'));
cout << m - 1 + n - 1 << "\n";
for(int i = 1; i < n; i++){
for(int j = 1; j < m; j++){
if((i + j) & 1){
grid[i][j] = '-';
}
}
}
for(int i = 1; i <= m; i++){
grid[n][i] = '-';
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cout << grid[i][j];
}
cout << "\n";
}
}
/////////////////////////////////////
int Choice1(int n, int m){
int x = n / 2;
if(x * 2 == n){
x--;
}
return x + m;
}
int Choice2(int n, int m){
int x = m / 2;
if(x * 2 == m){
x--;
}
return x + n;
}
void Subtask1and2(int n, int m){
if(Choice1(n, m) > Choice2(n, m)){
cout << Choice1(n, m) << "\n";
int x = Choice1(n, m) - m;
vector<vector<char>>grid(n + 1, vector<char>(m + 1, '-'));
for(int i = 1; i <= x; i++){
for(int j = 1; j <= m; j++){
grid[i][j] = '+';
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cout << grid[i][j];
}
cout << "\n";
}
}else{
cout << Choice2(n, m) << "\n";
int x = Choice2(n, m) - n;
vector<vector<char>>grid(n + 1, vector<char>(m + 1, '+'));
for(int i = 1; i <= x; i++){
for(int j = 1; j <= n; j++){
grid[j][i] = '-';
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cout << grid[i][j];
}
cout << "\n";
}
}
}
///////////////////////
void solve(){
int n, m;
cin >> n >> m;
if(min(n, m) <= 4){
Subtask1and2(n, m);
}else if((n & 1) && (m & 1)){
Subtask4(n, m);
}
}
int main(){
int t;
// t = 1;
cin >> t;
while(t--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Incorrect |
2 ms |
372 KB |
Wrong answer |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
1220 KB |
Output is correct |
2 |
Correct |
30 ms |
1788 KB |
Output is correct |
3 |
Correct |
34 ms |
1876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
724 KB |
Wrong answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Incorrect |
2 ms |
372 KB |
Wrong answer |
5 |
Halted |
0 ms |
0 KB |
- |