이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |