This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
bool remender(ll a , ll b){return a%b;}
//freopen("problemname.in", "r", stdin);
//freopen("problemname.out", "w", stdout);
void solve(){
int n , m;
cin >> n >> m;
int dp[n+1][m+1];
int mnn = m/2 + 1,mnm = n/2 + 1;
int ans = 0;
array<int,3> pos;
for(int i = 0; i <= n; i++){
for(int j = 0; j <= mnn; j++){
dp[i][j] = i;
if(i <= n-mnm)dp[i][j] += j;
int rem = m - j;
if(rem){
int total = i*mnn-j*i;
int less = total / rem;
int some = total % rem;
if(less+1 <= n-mnm)dp[i][j] += some;
if(less <= n-mnm)dp[i][j] += rem - some;
}
if(dp[i][j] > ans){
ans = dp[i][j];
pos = {0,i,j};
}
}
}
cout << ans << '\n';
char res[n][m];
if(pos[0] == 0){
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
res[i][j] = '-';
}
}
for(int i = 0; i < pos[1]; i++){
for(int j = 0; j < pos[2]; j++){
res[i][j] = '+';
}
}
int left = pos[2] , cur = left;
for(int i = 0; i < pos[1]; i++){
int cnt = 0;
while(cnt < mnn-pos[2]){
cnt++;
res[i][cur] = '+';
cur++;
if(cur == m)cur = left;
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++)cout << res[i][j];
cout << '\n';
}
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;cin>>t;
while(t--){
solve();
}
return 0;
}
Compilation message (stderr)
stones.cpp: In function 'void solve()':
stones.cpp:59:15: warning: 'pos.std::array<int, 3>::_M_elems[2]' may be used uninitialized in this function [-Wmaybe-uninitialized]
59 | res[i][j] = '+';
| ~~~~~~~~~~^~~~~
stones.cpp:63:20: warning: 'pos.std::array<int, 3>::_M_elems[1]' may be used uninitialized in this function [-Wmaybe-uninitialized]
63 | for(int i = 0; i < pos[1]; i++){
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |