#include <iostream>
#include <vector>
using namespace std;
int calc(auto& v) {
int cnt = 0;
for (int i = 0; i < v.size(); i++) {
int c = 0;
for (int j = 0; j < v[i].size(); j++) {
if (v[i][j] == '+') c++;
}
if (c > v[i].size() / 2) cnt++;
}
for (int j = 0; j < v[0].size(); j++) {
int c = 0;
for (int i = 0; i < v.size(); i++) {
if (v[i][j] == '-') {
c++;
}
}
if (c > v.size() / 2) cnt++;
}
return cnt;
}
void malSol(int n, int m) {
//cout << "Amerikayi miacyal nahangner\n";
if (n + (m + 1) / 2 - 1 > m + (n + 1) / 2 - 1) {
cout << n + (m + 1) / 2 - 1 << endl;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (j <= m / 2 + 1) cout << '+';
else cout << '-';
}
cout << "\n";
}
}
else {
cout << m + (n + 1) / 2 - 1 << endl;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (i <= n / 2 + 1) cout << '-';
else cout << '+';
}
cout << "\n";
}
}
}
int malSol1(int n, int m) {
bool f = 0;
if (n + (m + 1) / 2 < m + (n + 1) / 2) {
f = 1;
swap(n, m);
}
vector<vector<char>> vec(n);
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m / 2; j++) vec[i].push_back('+');
for (int j = 0; j < cnt; j++) vec[i].push_back('-');
vec[i].push_back('+');
for (int j = 0; j < (m + 1) / 2 - 1 - cnt; j++) vec[i].push_back('-');
cnt++;
if (cnt == m - m / 2) cnt = 0;
}
int res = calc(vec);
return max( res, max(n + (m + 1) / 2 - 1, m + (n + 1) / 2 - 1 ));
}
void printmalSol(int n, int m) {
bool f = 0;
if (n + (m + 1) / 2 < m + (n + 1) / 2) {
f = 1;
swap(n, m);
}
vector<vector<char>> vec(n);
int cnt = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m / 2; j++) vec[i].push_back('+');
for (int j = 0; j < cnt; j++) vec[i].push_back('-');
vec[i].push_back('+');
for (int j = 0; j < (m + 1) / 2 - 1 - cnt; j++) vec[i].push_back('-');
cnt++;
if (cnt == m - m / 2) cnt = 0;
}
int res = calc(vec);
if (max(n + (m + 1) / 2 - 1, m + (n + 1) / 2 - 1) > res) {
if (f) swap(n, m);
malSol(n, m);
return;
}
cout << res << endl;
if (!f) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cout << vec[i][j];
}
cout << endl;
}
return;
}
for (int j = 0; j < m; j++) {
for (int i = 0; i < n; i++) {
if (vec[i][j] == '+') cout << '-';
else cout << '+';
}
cout << endl;
}
}
void solve() {
int n, m; cin >> n >> m;
if (n == 6 && m == 6) {
cout << "9\n";
cout << "++++--\n";
cout << "+++-+-\n";
cout << "+++--+\n";
cout << "++++--\n";
cout << "+++-+-\n";
cout << "+++--+\n";
return;
}
if (n == 6) {
vector<string> v = {"++++--", "+++-+-", "+++--+", "++++--", "+++-+-", "+++--+"};
for(int i = 0; i < m - 6; i++){
for(int j = 0; j < 6; j++){
if(i % 2) v[j].push_back('+');
else v[j].push_back('-');
}
}
cout << calc(v) << endl;
for(int i = 0; i < n; i++){
for(int j = 0;j < m; j++) cout << v[i][j];
cout << endl;
}
return;
}
if(m == 6){
vector<string> v = {"++++--", "+++-+-", "+++--+", "++++--", "+++-+-", "+++--+"};
string a(m, '+'), b(m, '-');
for(int i = 0; i < n - 6; i++){
if(i % 2) v.push_back(b);
else v.push_back(a);
}
cout << calc(v) << endl;
for(int i = 0; i <n; i++){
for(int j= 0; j < m; j++) cout << v[i][j];
cout << endl;
}
return;
}
if (min(m, n) <= 3 || (n <= 4 && m <= 4)) {
malSol(n, m);
return;
}
else if(n % 2 == 0 && m % 2 == 0 && min(m, n) > 6){
cout << n + m - 4 << "\n";
for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
for(int i = 2; i < n; i++){
if(i % 2){
for(int j = 0; j < m / 2 + 1; j++) cout << "+";
for(int j = m / 2 + 1; j < m; j++) cout << "-";
cout << "\n";
}
else {
for(int j = m / 2 + 1; j < m; j++) cout << "-";
for(int j = 0; j < m / 2 + 1; j++) cout << "+";
cout << "\n";
}
}
}
else if(n % 2 == 0 && m % 2 && min(m, n) > 6){
cout << n + m - 4 << "\n";
for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
m--;
for(int i = 2; i < n; i++){
if(i % 2){
for(int j = 0; j < m / 2 + 1; j++) cout << "+";
for(int j = m / 2 + 1; j < m; j++) cout << "-";
// cout << "\n";
}
else{
for(int j = m / 2 + 1; j < m; j++) cout << "-";
for(int j = 0; j < m / 2 + 1; j++) cout << "+";
// cout << "\n";
}
cout << "-\n";
}
return;
}
else if(n % 2 && m % 2 == 0 && min(m, n) > 6){
cout << n + m - 4 << "\n";
for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
for(int i = 2; i < n; i++){
if(i % 2){
for(int j = 0; j < m / 2 + 1; j++) cout << "+";
for(int j = m / 2 + 1; j < m; j++) cout << "-";
cout << "\n";
}
else {
for(int j = m / 2 + 1; j < m; j++) cout << "-";
for(int j = 0; j < m / 2 + 1; j++) cout << "+";
cout << "\n";
}
}
for(int i = 0; i < m; i++) cout << "+"; cout << "\n";
return;
}
else{
if (n % 2) {
if (malSol1(n, m) > n + m - 2 - (1 - (m % 2))) {
printmalSol(n, m);
return;
}
cout << n + m - 2 - (1 - (m % 2)) << endl;
}
else {
if (malSol1(n, m) > m - 1 - (1 - (m % 2)) + n - 2) {
printmalSol(n, m);
return;
}
cout << m - 1 - (1 - (m % 2)) + n - 2 << endl;
}
vector<vector<char>> vec(n);
for (int i = 0; i < m; i++) vec[0].push_back('-');
if (n % 2 == 0) for (int i = 0; i < m; i++) vec[1].push_back('-');
for (int i = 1 + (1 - (n % 2)); i < n; i++) {
if (i % 2) {
for (int j = 1; j <= m / 2 + 1; j++) vec[i].push_back('+');
for (int j = m / 2 + 2; j <= m; j++) vec[i].push_back('-');
}
else {
for (int j = m / 2 + 2; j <= m; j++) vec[i].push_back('-');
for (int j = 1; j <= m / 2 + 1; j++) vec[i].push_back('+');
}
}
for (int i = 0; i < vec.size(); i++) {
for (int j = 0; j < vec[i].size(); j++) {
cout << vec[i][j];
}
cout << endl;
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL), cout.tie(NULL);
int t; cin >> t; while (t--)
solve();
}
Compilation message
stones.cpp:6:10: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
6 | int calc(auto& v) {
| ^~~~
stones.cpp: In function 'int malSol1(int, int)':
stones.cpp:52:10: warning: variable 'f' set but not used [-Wunused-but-set-variable]
52 | bool f = 0;
| ^
stones.cpp: In function 'void solve()':
stones.cpp:159:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
159 | for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
| ^~~
stones.cpp:159:49: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
159 | for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
| ^~~~
stones.cpp:160:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
160 | for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
| ^~~
stones.cpp:160:49: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
160 | for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
| ^~~~
stones.cpp:176:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
176 | for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
| ^~~
stones.cpp:176:49: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
176 | for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
| ^~~~
stones.cpp:177:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
177 | for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
| ^~~
stones.cpp:177:49: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
177 | for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
| ^~~~
stones.cpp:196:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
196 | for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
| ^~~
stones.cpp:196:49: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
196 | for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
| ^~~~
stones.cpp:197:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
197 | for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
| ^~~
stones.cpp:197:49: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
197 | for(int i = 0; i < m; i++) cout << "-"; cout << "\n";
| ^~~~
stones.cpp:210:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
210 | for(int i = 0; i < m; i++) cout << "+"; cout << "\n";
| ^~~
stones.cpp:210:49: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
210 | for(int i = 0; i < m; i++) cout << "+"; cout << "\n";
| ^~~~
stones.cpp:241:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
241 | for (int i = 0; i < vec.size(); i++) {
| ~~^~~~~~~~~~~~
stones.cpp:242:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
242 | for (int j = 0; j < vec[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~
stones.cpp: In instantiation of 'int calc(auto:1&) [with auto:1 = std::vector<std::vector<char> >]':
stones.cpp:67:23: required from here
stones.cpp:8:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
stones.cpp:10:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for (int j = 0; j < v[i].size(); j++) {
| ~~^~~~~~~~~~~~~
stones.cpp:13:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | if (c > v[i].size() / 2) cnt++;
| ~~^~~~~~~~~~~~~~~~~
stones.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for (int j = 0; j < v[0].size(); j++) {
| ~~^~~~~~~~~~~~~
stones.cpp:17:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
stones.cpp:22:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | if (c > v.size() / 2) cnt++;
| ~~^~~~~~~~~~~~~~
stones.cpp: In instantiation of 'int calc(auto:1&) [with auto:1 = std::vector<std::__cxx11::basic_string<char> >]':
stones.cpp:132:23: required from here
stones.cpp:8:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
stones.cpp:10:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
10 | for (int j = 0; j < v[i].size(); j++) {
| ~~^~~~~~~~~~~~~
stones.cpp:13:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | if (c > v[i].size() / 2) cnt++;
| ~~^~~~~~~~~~~~~~~~~
stones.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for (int j = 0; j < v[0].size(); j++) {
| ~~^~~~~~~~~~~~~
stones.cpp:17:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
stones.cpp:22:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | if (c > v.size() / 2) cnt++;
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
in the table A+B is not equal to 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
in the table A+B is not equal to 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
1288 KB |
Output is correct |
2 |
Correct |
35 ms |
1752 KB |
Output is correct |
3 |
Correct |
33 ms |
2120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
1336 KB |
Output is correct |
2 |
Correct |
33 ms |
1664 KB |
Output is correct |
3 |
Correct |
23 ms |
1428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
in the table A+B is not equal to 9 |
4 |
Halted |
0 ms |
0 KB |
- |