이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
// 3 3
// -++
// +-+
// -++
// wlog N > M
// every row will have N/2+1 red stones
// then make rows
int main(){
int t;
cin>>t;
while(t--){
int n, m;
cin>>n>>m;
int ans = 0;
char mat[n][m];
if(n >= m){
int minus[m];
memset(minus, 0, sizeof minus);
for(int i = 0; i < n; i++){
int need = m/2 + 1;
for(int j = 0; j < m; j++){
if(minus[j] < n/2+1 && (m-j-1) >= need){
minus[j]++;
mat[i][j] = '-';
}
else{
mat[i][j] = '+';
need--;
}
}
ans++;
}
for(int i = 0; i < m; i++){
if(minus[i] >= n/2+1) ans++;
}
int to_break = 0, bgain = 0;
for(int b = 1; b <= n; b++){
int gain = 0;
for(int j = 0; j < m; j++){
if(minus[j] >= n/2+1) continue;
if(minus[j] + b >= n/2+1) gain++;
}
if(bgain < gain - b){
bgain = gain-b;
to_break = b;
}
}
ans += bgain;
for(int i = 0; i < to_break; i++){
for(int j = 0; j < m; j++){
mat[i][j]='-';
}
}
cout<<ans<<"\n";
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++)
cout<<mat[i][j];
cout<<endl;
}
}
else{
int plus[n];
memset(plus, 0, sizeof plus);
for(int j = 0; j < m; j++){
int need = n/2 + 1;
for(int i = 0; i < n; i++){
if(plus[i] < m/2+1 && (n - i - 1) >= need){
mat[i][j] = '+';
plus[i]++;
}
else{
mat[i][j] = '-';
need--;
}
}
ans++;
}
for(int i = 0; i < n; i++)
if(plus[i] >= m / 2 + 1) ans++;
int to_break = 0, bgain = 0;
for(int b = 1; b <= m; b++){
int gain = 0;
for(int i = 0; i < n; i++){
if(plus[i] >= m/2+1) continue;
else if(plus[i] + b >= m/2+1) gain++;
}
if(bgain < gain-b){
bgain = gain-b;
to_break = b;
}
}
ans += bgain;
for(int j = 0; j < to_break; j++){
for(int i = 0; i < n; i++)
mat[i][j] = '+';
}
cout<<ans<<"\n";
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++)
cout<<mat[i][j];
cout<<endl;
}
}
}
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... |