#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define fi first
#define se second
#define pld pair<ld,ld>
#define pll pair<ll,ll>
#define sqr(a) ((a)*(a))
#define pii pair<int,int>
#define y1 Enkognit
#define sqr(a) ((a)*(a))
using namespace std;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
const ll md1=1e9+7, md2=998244357, md3=rnd()%(ll)(1e8), p1=31, p2=37, p3=41;
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n, m, k, l, r, i, j, a[1001][1001], b[1001], c[1001];
pll next(pll o)
{
if (o.se==m) o.fi++, o.se=1; else o.se++;
return o;
}
ll check()
{
ll ans=0;
for (int i = 1; i <= n; i++)
{
ll o=0;
for (int j = 1; j <= m; j++) o+=(a[i][j]==0);
ans+=(o>m/2);
}
for (int i = 1; i <= m; i++)
{
ll o=0;
for (int j = 1; j <= n; j++) o+=(a[j][i]);
ans+=(o>n/2);
}
return ans;
}
void rec(pll u)
{
ll i=u.fi, j=u.se;
//cout << i << " " << j << "\n";
a[i][j]=1;
if (i==n && j==m)
{
ll p=check();
if (p>15)
{
cout << p << "\n";
for (int i = 1 ;i <= n; i++)
{
for (int j = 1;j <= m; j++)
cout << a[i][j] << " ";
cout << "\n";
}
system("pause");
}
}else rec(next(mp(i,j)));
a[i][j]=0;
if (i==n && j==m)
{
ll p=check();
if (p>15)
{
cout << p << "\n";
for (int i = 1 ;i <= n; i++)
{
for (int j = 1;j <= m; j++)
cout << a[i][j] << " ";
cout << "\n";
}
system("pause");
}
}else rec(next(mp(i,j)));
}
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
//ios_base::sync_with_stdio(0);
//cin.tie(0);
//n=3, m=14;
//rec(mp(1,1));
ll q;
cin >> q;
while (q--)
{
cin >> n >> m;
for (int i = 1; i <= max(n,m); i++) b[i]=0,c[i]=0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {a[i][j]=(i+j)%2;b[i]+=((i+j)%2==0);c[j]+=(i+j)%2;}
for (int i = 1; i <= m; i++)
if (c[i]==n/2 && a[1][i]==0)
{
a[1][i]=1;
b[1]--;
c[i]++;
}
if (n%2==0)
for (int i = 1; i <= m; i++)
if (c[i]==n/2 && a[n][i]==0)
{
a[n][i]=1;
b[n]--;
c[i]++;
}
for (int i = 1; i <= n; i++)
if (b[i]==m/2 && a[i][1]==1)
{
a[i][1]=0;
c[1]--;
b[i]++;
}
if (m%2==0)
for (int i = 1; i <= n; i++)
if (b[i]==m/2 && a[i][m]==1)
{
a[i][m]=0;
c[m]--;
b[i]++;
}
ll ans=0;
for (int i = 1; i <= n; i++) if (b[i]>m/2) {ans++;}
//cout << "\n";
for (int i = 1; i <= m; i++) if (c[i]>n/2) {ans++;}
if ((m+(n+1)/2-1)/((n+1)/2)<(m+1)/2 && ans<m+(n+1)/2 && m+(n+1)/2>(n-1)/2+m && n+(m+1)/2<=m+(n+1)/2)
{
cout << m+(n+1)/2 << "\n";
for (int i = 1; i <= n/2; i++)
{
for (int j = 1; j <= m; j++) cout << "-";
cout << "\n";
}
ll l=1;
for (int i = n/2+1; i <= n; i++)
{
for (int j = 1; j <= m; j++) if (j%((n+1)/2)==l%((n+1)/2)) cout << "-"; else cout << "+";
cout << "\n";
l++;
}
continue;
}
if ((n+(m+1)/2-1)/((m+1)/2)<(n+1)/2 && ans<n+(m+1)/2 && n+(m+1)/2>(m-1)/2+n)
{
cout << n+(m+1)/2 << "\n";
ll l=1;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= (m+1)/2; j++) if (j%((m+1)/2)==l%((m+1)/2)) cout << "+"; else cout << "-";
for (int j = (m+1)/2+1; j <= m; j++) cout << "+";
l++;
cout << "\n";
}
continue;
}
//cout << "\n";
if (ans>=(n-1)/2+m && ans>=(m-1)/2+n)
{
cout << ans << "\n";
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
if (a[i][j]) cout << '-'; else cout << "+";
cout << "\n";
}
}else
if (ans<=(n-1)/2+m && (n-1)/2+m>=(m-1)/2+n)
{
cout << (n-1)/2+m << "\n";
for (int i = 1; i <= (n-1)/2; i++)
{
for (int j = 1; j <= m; j++) cout << "+";
cout << "\n";
}
for (int i = (n-1)/2+1; i <= n; i++)
{
for (int j = 1; j <= m; j++) cout << "-";
cout << "\n";
}
}else
if (ans<=(m-1)/2+n && (n-1)/2+m<=(m-1)/2+n)
{
cout << (m-1)/2+n << "\n";
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= (m-1)/2; j++) cout << "-";
for (int j = (m-1)/2+1; j <= m; j++) cout << "+";
cout << "\n";
}
}
}
}
Compilation message
stones.cpp: In function 'void rec(std::pair<long long int, long long int>)':
stones.cpp:73:19: warning: ignoring return value of 'int system(const char*)', declared with attribute warn_unused_result [-Wunused-result]
system("pause");
~~~~~~^~~~~~~~~
stones.cpp:89:19: warning: ignoring return value of 'int system(const char*)', declared with attribute warn_unused_result [-Wunused-result]
system("pause");
~~~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
Correct |
6 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
1764 KB |
Output is correct |
2 |
Correct |
44 ms |
7112 KB |
Output is correct |
3 |
Correct |
43 ms |
8568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
2240 KB |
Output is correct |
2 |
Correct |
42 ms |
6804 KB |
Output is correct |
3 |
Correct |
38 ms |
5576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
Correct |
6 ms |
632 KB |
Output is correct |
5 |
Correct |
47 ms |
1764 KB |
Output is correct |
6 |
Correct |
44 ms |
7112 KB |
Output is correct |
7 |
Correct |
43 ms |
8568 KB |
Output is correct |
8 |
Correct |
46 ms |
2240 KB |
Output is correct |
9 |
Correct |
42 ms |
6804 KB |
Output is correct |
10 |
Correct |
38 ms |
5576 KB |
Output is correct |
11 |
Incorrect |
16 ms |
632 KB |
Wrong answer in test 26 8: 30 < 31 |
12 |
Halted |
0 ms |
0 KB |
- |