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>
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
using namespace std;
typedef long long lint;
typedef pair<int,int> ii;
pair<int, vector<string> > solve(int rows, int cols){
vector<string> res;
for(int r = 0;r < rows;r++){
res.push_back("");
for(int c = 0;c < cols;c++){
res.back() += '-';
}
}
int ans = cols;
vector<int> F;
F.assign(cols, 0);
int c = 0;
int needcol = (cols / 2) + 1;
int maxrow = ((rows-1) / 2);
int row = 0;
int take = 0;
while(true){
if(F[c] == maxrow) break;
res[row][c] = '+';
F[c]++;
c++; if(c == cols) c = 0;
take++;
if(take % needcol == 0){
row++;
ans++;
}
}
return {ans, res};
}
vector<string> trans(vector<string> O){
int rows = sz(O[0]);
int cols = sz(O);
vector<string> res;
for(int r = 0;r < rows;r++){
res.push_back("");
for(int c = 0;c < cols;c++){
res.back() += '-';
}
}
for(int r = 0;r < rows;r++){
for(int c = 0;c < cols;c++){
res[r][c] = O[c][r];
if(res[r][c] == '-') res[r][c] = '+';
else res[r][c] = '-';
}
}
return res;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int Q; cin >> Q;
while(Q--){
int rows, cols; cin >> rows >> cols;
if(rows <= cols){
auto res = solve(rows, cols);
cout << res.first << "\n";
for(string s : res.second){
cout << s << "\n";
}
}
else{
auto Rres = solve(cols, rows);
auto res = trans(Rres.second);
cout << Rres.first << "\n";
for(string s : res){
cout << s << "\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... |