#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;
typedef vector <ll> vl;
typedef vector <int> vi;
typedef vector <bool> vb;
typedef vector <vector <int> > vvi;
typedef vector <vector <ll> > vvl;
typedef vector <pair<int,int> > vii;
typedef vector <pair<ll,ll> > vll;
string itos(int n) {stringstream ss;ss<<n;string s=ss.str();return s;}
ll ppow(ll x,ll y,ll mod) {
ll res=1;
while(y) {
if(y&1) res=res*x%mod;
y>>=1;
x=x*x%mod;
}
return res;
}
const int N=1005;
char a1[N][N],a2[N][N];
int w[N],h[N];
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;
cin >> t;
while (t--) {
int n,m;
cin >> n >> m;
/*int mx=max(m/2-1+m%2+n,n/2-1+n%2+m);
cout << mx << "\n";
if (mx == m/2-1+m%2+n) {
for (int i=1;i<=n;++i) {
for (int j=1;j<=m;++j) {
if (j <= m/2-1+m%2) {
cout << '-';
}
else {
cout << '+';
}
}
cout << "\n";
}
}
else {
for (int i=1;i<=n;++i) {
for (int j=1;j<=m;++j) {
if (i <= n/2-1+n%2) {
cout << '+';
}
else {
cout << '-';
}
}
cout << "\n";
}
}*/
set<int> s;
for (int i=1;i<=m;++i) {
s.insert(i);
}
for (int i=1;i<=n;++i) {
for (int j=1;j<=m;++j) {
a1[i][j]='-';
h[j]=0;
}
w[i]=0;
}
int d=1;
for (int i=1;i<=n;++i) {
int cur=0;
if (d == (n+1)/2) {
break;
}
int need=(m+1)/2+1-m%2;
while (s.size() && cur < need) {
a1[i][*s.begin()]='+';
s.erase(s.begin());
cur++;
}
if (cur < need) {
d++;
if (d == (n+1)/2) break;
for (int j=1;j<=m;++j) {
s.insert(j);
}
}
else
continue;
for (int j=1;j<=m;++j) {
if (cur == need) break;
if (a1[i][j] == '-') {
a1[i][j]='+';
s.erase(j);
cur++;
}
}
}
int ans1=0;
for (int i=1;i<=n;++i) {
for (int j=1;j<=m;++j) {
if (a1[i][j] == '+') {
w[i]++;
}
else {
h[j]++;
}
}
}
for (int i=1;i<=n;++i) {
if (w[i] > m/2)
ans1++;
w[i]=0;
}
for (int j=1;j<=m;++j) {
if (h[j] > n/2) {
ans1++;
}
h[j]=0;
}
int ans2=0;
s.clear();
for (int i=1;i<=n;++i) {
s.insert(i);
}
for (int i=1;i<=n;++i) {
for (int j=1;j<=m;++j) {
a2[i][j]='+';
h[j]=0;
}
w[i]=0;
}
d=1;
for (int i=1;i<=m;++i) {
int cur=0;
if (d == (m+1)/2) {
break;
}
int need=(n+1)/2+1-n%2;
while (s.size() && cur < need) {
a2[*s.begin()][i]='-';
s.erase(s.begin());
cur++;
}
if (cur < need) {
d++;
if (d == (m+1)/2) break;
for (int j=1;j<=n;++j) {
s.insert(j);
}
}
else
continue;
for (int j=1;j<=n;++j) {
if (cur == need) break;
if (a2[j][i] == '-') {
a2[j][i]='+';
s.erase(j);
cur++;
}
}
}
for (int i=1;i<=n;++i) {
for (int j=1;j<=m;++j) {
if (a2[i][j] == '+') {
w[i]++;
}
else {
h[j]++;
}
}
}
for (int i=1;i<=n;++i) {
if (w[i] > m/2)
ans2++;
w[i]=0;
}
for (int j=1;j<=m;++j) {
if (h[j] > n/2) {
ans2++;
}
h[j]=0;
}
cout << max(ans1,ans2) << "\n";
if (ans1 > ans2) {
for (int i=1;i<=n;++i) {
for (int j=1;j<=m;++j) {
cout << a1[i][j];
}
cout << "\n";
}
}
else {
for (int i=1;i<=n;++i) {
for (int j=1;j<=m;++j) {
cout << a2[i][j];
}
cout << "\n";
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Incorrect |
6 ms |
552 KB |
Wrong answer in test 37 5: 39 < 40 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
120 ms |
1536 KB |
Wrong answer in test 97 21: 112 < 116 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
123 ms |
1720 KB |
Output is correct |
2 |
Correct |
116 ms |
2636 KB |
Output is correct |
3 |
Correct |
103 ms |
2368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
4 ms |
504 KB |
Output is correct |
4 |
Incorrect |
6 ms |
552 KB |
Wrong answer in test 37 5: 39 < 40 |