#pragma GCC optimize ("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"
#define pb push_back
#define vll vector<long long>
#define vb vector<bool>
#define vi vector<int>
#define vs vector<string>
#define vpii vector< pair<int, int> >
#define pii pair<int, int>
#define pbb pair<bool, bool>
#define pll pair<long long, long long>
#define vvi vector< vector<int> >
#define ld long double
#define mp make_pair
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;
int main()
{
int t;
cin >> t;
while(t--)
{
int n, m;
cin >> n >> m;
int cnt = 0;
int ans = 0;
char res[n + 5][m + 5];
if(min(n, m) == 6)
{
if(n == 6)
{
for(int i = 1; i <= n; i++)
for(int a = 1; a <= m; a++)
res[i][a] = '-';
for(int i = 1; i <= 4; i++)
res[1][i] = '+';
for(int i = 3; i <= 6; i++)
res[2][i] = '+';
res[3][1] = res[3][2] = res[3][5] = res[3][6] = '+';
//cout << 3 + m << "\n";
ans = m + 3;
} else
{
for(int i = 1; i <= n; i++)
for(int a = 1; a <= m; a++)
res[i][a] = '+';
for(int i = 1; i <= 4; i++)
res[i][1] = '+';
for(int i = 3; i <= 6; i++)
res[i][2] = '+';
res[1][3] = res[2][3] = res[5][3] = res[6][3] = '-';
//cout << 3 + n << "\n";
ans = n + 3;
}
}
else if(n > m)
{
//fill(res, sizeof(res), '+');
ans = n;
for(int i = 1; i <= n; i++)
for(int a = 1; a <= m; a++)
res[i][a] = '+';
int i = 1;
for(i = 1; i <= m; i++)
{
if(cnt + 1 >= (m+1) / 2)
break;
for(int a = 1; a <= n / 2 + 1; a++)
res[a][i] = '-';
ans++;
cnt++;
}
int torem = 1;
if(m % 2 == 0)
torem++;
if((n % 2 == 0 && m - i - torem + 1 >= 2) || (n % 2 == 1 && m - i - torem + 1 >= 1)) {
ans--;
if(n % 2 == 0)
ans--;
cnt = 0;
for(; i <= m; i++)
{
if(cnt + 1 >= (m+1) / 2)
break;
for(int a = (n+1)/2; a <= n; a++)
res[a][i] = '-';
ans++;
cnt++;
}
}
} else
{
//fill(res, sizeof(res), '-');
ans = m;
for(int i = 1; i <= n; i++)
for(int a = 1; a <= m; a++)
res[i][a] = '-';
int i = 1;
//cnt = 0;
for(i = 1; i <= n; i++)
{
if(cnt + 1 >= (n+1) / 2)
break;
for(int a = 1; a <= m / 2 + 1; a++)
res[i][a] = '+';
ans++;
cnt++;
}
int torem = 1;
if(n % 2 == 0)
torem++;
if((m % 2 == 0 && n - i - torem + 1 >= 2) || (m % 2 == 1 && n - i - torem + 1 >= 1)) {
//break;
ans--;
if(m % 2 == 0)
ans--;
cnt = 0;
for(; i <= n; i++)
{
if(cnt + 1 >= (n+1) / 2)
break;
for(int a = (m+1)/2; a <= m; a++)
res[i][a] = '+';
ans++;
cnt++;
}
}
}
cout << ans << "\n";
for(int i = 1; i <= n; i++)
{
for(int a = 1; a <= m; a++)
cout << res[i][a];
cout << "\n";
}
}
}
Compilation message
stones.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
3 | #pragma GCC optimization ("unroll-loops")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Incorrect |
3 ms |
340 KB |
Wrong answer in test 38 5: 40 < 41 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
1256 KB |
Output is correct |
2 |
Correct |
29 ms |
1804 KB |
Output is correct |
3 |
Correct |
26 ms |
1788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
1200 KB |
Output is correct |
2 |
Correct |
24 ms |
1620 KB |
Output is correct |
3 |
Correct |
22 ms |
1324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
212 KB |
Output is correct |
4 |
Incorrect |
3 ms |
340 KB |
Wrong answer in test 38 5: 40 < 41 |
5 |
Halted |
0 ms |
0 KB |
- |