#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define pb push_back
#define all(a) a.begin(),a.end()
#define int long long
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
typedef vector<ll>vll;
typedef vector<int>vi;
typedef vector<bool>vb;
typedef vector<vi>vvi;
typedef vector<vll>vvll;
typedef vector<pi>vpi;
typedef vector<pll>vpll;
const int N=1e3+99;
char a[N][N];
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt;
cin>>tt;
while(tt--){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
a[i][j]='$';
}
}
cout<<max(n,m)+(min(n,m)-1)/2*max(n,m)/((max(n,m)+2)/2)<<"\n";
multiset<pi>st;
if(n<=m){
for(int i=1;i<=m;++i){
st.insert({0,i});
}
int cnt=0;
for(int i=1;i<=n;++i){
int cur=0;
bool ok=1;
while(cur<(m+2)/2){
auto [c,j]=*st.begin();
if(c>=(n-1)/2){
ok=false;
break;
}
else{
st.erase(st.begin());
st.insert({++c,j});
a[i][j]='+';
cur++;
}
}
if(ok){
cnt++;
}
}
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
if(a[i][j]=='+'){
cout<<'+';
}
else{
cout<<'-';
}
}
cout<<"\n";
}
}
else{
for(int i=1;i<=n;++i){
st.insert({0,i});
}
int cnt=0;
for(int i=1;i<=m;++i){
int cur=0;
bool ok=1;
while(cur<(n+2)/2){
auto [c,j]=*st.begin();
if(c>=(m-1)/2){
ok=false;
break;
}
else{
st.erase(st.begin());
st.insert({++c,j});
a[j][i]='-';
cur++;
}
}
if(ok){
cnt++;
}
}
for(int i=1;i<=n;++i){
for(int j=1;j<=m;++j){
if(a[i][j]=='-'){
cout<<'-';
}
else{
cout<<'+';
}
}
cout<<"\n";
}
}
}
}
Compilation message
stones.cpp: In function 'int main()':
stones.cpp:53:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
53 | auto [c,j]=*st.begin();
| ^
stones.cpp:90:26: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
90 | auto [c,j]=*st.begin();
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
396 KB |
Output is correct |
4 |
Correct |
4 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
1448 KB |
Output is correct |
2 |
Correct |
58 ms |
2056 KB |
Output is correct |
3 |
Correct |
58 ms |
2152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
1388 KB |
Output is correct |
2 |
Correct |
52 ms |
1824 KB |
Output is correct |
3 |
Correct |
51 ms |
1696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
3 ms |
396 KB |
Output is correct |
4 |
Correct |
4 ms |
332 KB |
Output is correct |
5 |
Correct |
70 ms |
1448 KB |
Output is correct |
6 |
Correct |
58 ms |
2056 KB |
Output is correct |
7 |
Correct |
58 ms |
2152 KB |
Output is correct |
8 |
Correct |
61 ms |
1388 KB |
Output is correct |
9 |
Correct |
52 ms |
1824 KB |
Output is correct |
10 |
Correct |
51 ms |
1696 KB |
Output is correct |
11 |
Correct |
16 ms |
580 KB |
Output is correct |
12 |
Correct |
58 ms |
1976 KB |
Output is correct |
13 |
Correct |
60 ms |
2140 KB |
Output is correct |
14 |
Correct |
41 ms |
1668 KB |
Output is correct |
15 |
Correct |
73 ms |
2372 KB |
Output is correct |
16 |
Correct |
59 ms |
1860 KB |
Output is correct |
17 |
Correct |
23 ms |
1332 KB |
Output is correct |