이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define io \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
ll bp(ll n,ll m){
if(m == 0){
return 1;
}
if(m == 1){
return n;
}
if(m%2==0){
return bp(n*n,m/2);
}
return n*bp(n,m-1);
}
const int N = 1020, M = 33, inf = 1e9 + 99;
const ll inff = 1e12;
void solve() {
int n,m;
cin >> n >> m;
vector<vector<int>>a(n + 1 , vector<int>(m + 1 , 0));
if(n <= 4 && m <= 4) {
if(n<=m) {
cout << (n-1)/2 + m << endl;
int x = (n-1)/2;
for(int i=1;i<=n - x;i++) {
for(int j=1;j<=m;j++) {
a[i][j] = -1;
}
}
for(int i=1;i<=x; i++) {
for(int j=1;j<=m;j++) {
a[i][j] = 1;
}
}
}
else {
cout << (m-1)/2+n << endl;
int x = (m-1)/2;
for(int i=1;i<=n;i++) {
for(int j=1;j<=x;j++) {
a[i][j] = -1;
}
for(int j=1;j<=m- x;j++){
a[i][j] = 1;
}
}
}
}
else if(n == m && n%2==0 && m%2==0) {
for(int i=1;i<=n;i++) {
for(int j=1;j<=3;j++){
a[i][j] = 1;
}
}
int tmp=(n/2 - 2)*n, x=1, y=n;
while(tmp > 0) {
tmp--;
a[x][y] = 1;
x++;
y--;
if(y==3){
y=n;
}
if(x==n+1){
x=1;
}
}
cout << n + m - 3 << endl;
}
else {
for(int i=1; i<=n-(n-1)/2; i++) {
for(int j=1; j<=(m-1)/2; j++) {
a[i][j] = -1;
}
}
for(int i=(n-1)/2+1;i<=n;i++) {
for(int j=(m)/2+2;j<=m;j++) {
a[i][j] = -1;
}
}
cout << 2*((n-1)/2 + (m-1)/2) << endl;
}
for(int i=1;i<=n;i++) {
for(int j=1;j<=m;j++) {
cout << (a[i][j] == 1 ? '+' : '-');
}
cout<<endl;
}
}
int main()
{
io;
int t;
cin >> t;
while(t--) {
solve();
}
return 0;
}
# | 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... |