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;
int cnt[1005];
char ans[1005][1005];
int go1(int n, int m){
memset(cnt, 0, sizeof cnt);
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
ans[i][j] = '-';
cnt[j] = n;
}
}
int l = 1, tot = m;
for(int i = 1; i <= n; i++){
int need = m / 2 + 1, cur = l;
while(need > 0){
if(cnt[cur] > n / 2 + 1){
cnt[cur]--;
need--;
ans[i][cur] = '+';
}
cur++;
if(cur > m)cur -= m;
if(cur == l)break;
}
if(need == 0){
tot++;
l = cur;
}else break;
}
return tot;
}
int go2(int n, int m){
memset(cnt, 0, sizeof cnt);
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
ans[i][j] = '+';
}
cnt[i] = m;
}
int l = 1, tot = n;
for(int j = 1; j <= m; j++){
int need = n / 2 + 1, cur = l;
while(need > 0){
if(cnt[cur] > m / 2 + 1){
cnt[cur]--;
need--;
ans[cur][j] = '-';
}
cur++;
if(cur > n)cur -= n;
if(cur == l)break;
}
if(need == 0){
tot++;
l = cur;
}else break;
}
return tot;
}
int main(){
int t;
cin >> t;
while(t--){
int n, m;
cin >> n >> m;
if(go1(n, m) > go2(n, m)){
cout << go1(n, m) << '\n';
}else{
cout << go2(n, m) << '\n';
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cout << ans[i][j];
}
cout << '\n';
}
}
}
# | 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... |