#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define PI 3.14159265359
ll n,m,t,p[1001][1001],h[1001][1001],a,b,c,d,e,f,i,j,k,mod=1000000007,mod1=998244353,MAX=1e18;
string s,u;
ll df[101];
vector<pair<ll,ll> >v;
vector<ll>dv[101];
void dfs(ll x){
df[x]=1;
for(ll i=0;i<dv[x].size();i++){
if(df[dv[x][i]]==0){
dfs(dv[x][i]);
}
}
}
ll fastPow(ll a,ll b){
ll d=1;
while(b>0){
if(b%2==1){
d=d*a%mod;
}
b/=2;
a=a*a%mod;
}
return d;
}
ll check(){
ll r=0;
ll b=0;
ll ans=0;
for(ll i=1;i<=n;i++){
r=0;
b=0;
for(ll j=1;j<=m;j++){
if(p[i][j]==1){
r++;
}
else{
b++;
}
}
if(r>b){
ans++;
}
}
for(ll i=1;i<=m;i++){
r=0;
b=0;
for(ll j=1;j<=n;j++){
if(p[j][i]==1){
r++;
}
else{
b++;
}
}
if(b>r){
ans++;
}
}
return ans;
}
int main(){
cin>>t;
while(t--){
cin>>n>>m;
a=fastPow(2,n*m);
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
v.pb({i,j});
}
}
ll ans=0;
for(i=0;i<a;i++){
d=i;
for(j=0;j<n*m;j++){
p[v[j].ff][v[j].ss]=d%2;
d/=2;
}
f=check();
if(ans<f){
ans=f;
for(j=1;j<=n;j++){
for(k=1;k<=m;k++){
h[j][k]=p[j][k];
}
}
}
}
cout<<ans<<endl;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(h[i][j]==1){
cout<<'+';
}
else{
cout<<'-';
}
}
cout<<endl;
}
v.clear();
}
}
Compilation message
stones.cpp: In function 'void dfs(long long int)':
stones.cpp:15:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(ll i=0;i<dv[x].size();i++){
| ~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
13 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2079 ms |
332 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
13 ms |
332 KB |
Output is correct |
3 |
Execution timed out |
2079 ms |
332 KB |
Time limit exceeded |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2069 ms |
1100 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2069 ms |
528 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
13 ms |
332 KB |
Output is correct |
3 |
Execution timed out |
2079 ms |
332 KB |
Time limit exceeded |