//
// C.cpp
// torelax
//
// Created by Rakhman on 1/5/21.
//
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>
#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define no_answer {cout << "NO"; exit(0);}
#define FOR(i, start, finish, k) for(llong i = start; i <= finish; i += k)
const long long mxn = 1e6 + 110;
const long long mnn = 1e3 + 2;
const long long mod = 1e9 + 7;
const long long inf = 1e18;
const long long OO = 1e9;
typedef long long llong;
typedef unsigned long long ullong;
using namespace std;
int n, m;
char ch[mnn][mnn];
void solve(){
int mx = 0, rows = -1, cols = -1;
bool swapped = false;
cin >> n >> m;
if(n < m) {
swapped = true;
swap(n, m);
}
for(int i = 0; i <= n; i++){
int x = (m - 1) / 2 * (n - i);
llong col = x / ((n + 1) / 2);
int lol = n - i + col;
if(lol > mx){
mx = lol;
rows = i;
cols = col;
}
if(col == m){
break;
}
}
cout << mx << nl;
for(int i = 1; i <= rows; i++){
for(int j = 1; j <= m; j++){
ch[i][j] = (swapped == true ? '+' : '-');
}
cout << nl;
}
for(int i = 1; i <= n - rows; i++){
for(int j = 1; j <= m; j++){
ch[i][j] = (swapped == true ? '-' : '+');
}
}
set<pair<int, int> > st;
for(int i = m - cols + 1; i <= m; i++){
st.insert({-1 * (n + 1) / 2 - rows, i});
}
for(int i = 1; i <= n - rows; i++){
vector<pair<int, int> > v;
for(int j = 1; j <= (m - 1) / 2; j++){
if(st.size() == 0) break;
pair<int, int> x = *(st.begin());
st.erase(st.begin());
ch[i][x.S] = (swapped == true ? '+' : '-');
v.push_back({x.F, x.S});
}
for(int j = 0; j < v.size(); j++){
if(v[j].F + 1 == 0) continue;
st.insert({v[j].F + 1, v[j].S});
}
}
if(swapped == 1){
for(int j = 1; j <= m; j++){
for(int i = 1; i <= n; i++){
cout << ch[i][j];
}
cout << nl;
}
}else{
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cout << ch[i][j];
}
cout << nl;
}
}
}
int main(){
int t;
cin >> t;
while(t--){
solve();
}
}
Compilation message
stones.cpp: In function 'void solve()':
stones.cpp:102:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
102 | for(int j = 0; j < v.size(); j++){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
in the table A+B is not equal to 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
384 KB |
in the table A+B is not equal to 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
in the table A+B is not equal to 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
1516 KB |
Output is correct |
2 |
Correct |
102 ms |
2156 KB |
Output is correct |
3 |
Correct |
99 ms |
2156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
101 ms |
1516 KB |
in the table A+B is not equal to 46 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
in the table A+B is not equal to 6 |