fef841b401 2020-08-01 kinaba: #include <iostream> fef841b401 2020-08-01 kinaba: #include <sstream> fef841b401 2020-08-01 kinaba: #include <iomanip> fef841b401 2020-08-01 kinaba: #include <vector> fef841b401 2020-08-01 kinaba: #include <string> fef841b401 2020-08-01 kinaba: #include <map> fef841b401 2020-08-01 kinaba: #include <set> fef841b401 2020-08-01 kinaba: #include <algorithm> fef841b401 2020-08-01 kinaba: #include <numeric> fef841b401 2020-08-01 kinaba: #include <iterator> fef841b401 2020-08-01 kinaba: #include <functional> fef841b401 2020-08-01 kinaba: #include <complex> fef841b401 2020-08-01 kinaba: #include <queue> fef841b401 2020-08-01 kinaba: #include <stack> fef841b401 2020-08-01 kinaba: #include <cmath> fef841b401 2020-08-01 kinaba: #include <cassert> fef841b401 2020-08-01 kinaba: #include <tuple> fef841b401 2020-08-01 kinaba: using namespace std; fef841b401 2020-08-01 kinaba: typedef long long LL; fef841b401 2020-08-01 kinaba: typedef complex<double> CMP; fef841b401 2020-08-01 kinaba: fef841b401 2020-08-01 kinaba: class RoomPairs { public: fef841b401 2020-08-01 kinaba: vector <string> fix(vector<string> s) { fef841b401 2020-08-01 kinaba: for (size_t y = 1; y < s.size(); y += 2) fef841b401 2020-08-01 kinaba: s[y][0] = s[y][s[y].size() - 1] = '|'; fef841b401 2020-08-01 kinaba: for (size_t x = 1; x < s[0].size(); x += 2) fef841b401 2020-08-01 kinaba: s[0][x] = s[s.size()-1][x] = '-'; fef841b401 2020-08-01 kinaba: fef841b401 2020-08-01 kinaba: for (size_t y = 0; y<s.size(); y += 2) fef841b401 2020-08-01 kinaba: for (size_t x = 0; x < s[y].size(); x += 2) { fef841b401 2020-08-01 kinaba: int dx[] = { -1, +1, 0, 0 }; fef841b401 2020-08-01 kinaba: int dy[] = { 0, 0, -1, +1 }; fef841b401 2020-08-01 kinaba: char c = ' '; fef841b401 2020-08-01 kinaba: for (int d = 0; d < 4; ++d) { fef841b401 2020-08-01 kinaba: int yy = y + dy[d]; fef841b401 2020-08-01 kinaba: int xx = x + dx[d]; fef841b401 2020-08-01 kinaba: if (0 <= yy && yy < s.size() && 0 <= xx && xx < s[0].size() && s[yy][xx] != ' ') fef841b401 2020-08-01 kinaba: c = '+'; fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: s[y][x] = c; fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: return s; fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: vector <string> construct(int R, int C, int N) fef841b401 2020-08-01 kinaba: { fef841b401 2020-08-01 kinaba: return fix(solve(R, C, N)); fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: fef841b401 2020-08-01 kinaba: vector<string> solve(int R, int C, int N) fef841b401 2020-08-01 kinaba: { fef841b401 2020-08-01 kinaba: vector<string> ans(R * 2 + 1, string(C * 2 + 1, ' ')); fef841b401 2020-08-01 kinaba: if (N < C) { fef841b401 2020-08-01 kinaba: for (int r=1; r < ans.size(); r+=2) { fef841b401 2020-08-01 kinaba: for (int c = 0; c < N; ++c) fef841b401 2020-08-01 kinaba: ans[r][c*2+2] = '|'; fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: return ans; fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: fef841b401 2020-08-01 kinaba: for (int r = 2; r <= R; ++r) fef841b401 2020-08-01 kinaba: if((r-1)*C+r*(C-1) >= N) fef841b401 2020-08-01 kinaba: { fef841b401 2020-08-01 kinaba: int cnt = (r - 2)*C + (r - 1)*(C - 1); fef841b401 2020-08-01 kinaba: fef841b401 2020-08-01 kinaba: vector<bool> h(C-1, true); fef841b401 2020-08-01 kinaba: vector<bool> v(C, false); fef841b401 2020-08-01 kinaba: for(; cnt<N; ++cnt) { fef841b401 2020-08-01 kinaba: if (h[0] == false) fef841b401 2020-08-01 kinaba: h[0] = true; fef841b401 2020-08-01 kinaba: else { fef841b401 2020-08-01 kinaba: int r = v.size() - 1; fef841b401 2020-08-01 kinaba: for (; r >= 0; --r) fef841b401 2020-08-01 kinaba: if (v[r] == false) fef841b401 2020-08-01 kinaba: break; fef841b401 2020-08-01 kinaba: if (r > 1) { fef841b401 2020-08-01 kinaba: v[r] = true; fef841b401 2020-08-01 kinaba: h[0] = false; fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: else { fef841b401 2020-08-01 kinaba: //.. fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: fef841b401 2020-08-01 kinaba: for (int x = 0; x < h.size(); ++x) { fef841b401 2020-08-01 kinaba: for (int y = 0; y < R; ++y) fef841b401 2020-08-01 kinaba: if(y<r-1) fef841b401 2020-08-01 kinaba: ans[1 + y * 2][2 + x * 2] = '|'; fef841b401 2020-08-01 kinaba: else fef841b401 2020-08-01 kinaba: ans[1 + y * 2][2 + x * 2] = (h[x] ? '|' : ' '); fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: for (int x = 0; x < v.size(); ++x) fef841b401 2020-08-01 kinaba: for (int y=0; y < R; ++y) fef841b401 2020-08-01 kinaba: if(y < r) fef841b401 2020-08-01 kinaba: ans[2 + y * 2][1 + x * 2] = '-'; fef841b401 2020-08-01 kinaba: else if(y==r) fef841b401 2020-08-01 kinaba: ans[2 + y * 2][1 + x * 2] = (v[x] ? '-' : ' '); fef841b401 2020-08-01 kinaba: fef841b401 2020-08-01 kinaba: return ans; fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: }; fef841b401 2020-08-01 kinaba: fef841b401 2020-08-01 kinaba: // BEGIN CUT HERE fef841b401 2020-08-01 kinaba: #include <ctime> fef841b401 2020-08-01 kinaba: double start_time; string timer() fef841b401 2020-08-01 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } fef841b401 2020-08-01 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) fef841b401 2020-08-01 kinaba: { os << "{ \n"; fef841b401 2020-08-01 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) fef841b401 2020-08-01 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : "\n"); os << " }"; return os; } fef841b401 2020-08-01 kinaba: void verify_case(const vector <string>& Expected, const vector <string>& Received) { fef841b401 2020-08-01 kinaba: bool ok = (Expected == Received); fef841b401 2020-08-01 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; fef841b401 2020-08-01 kinaba: cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } } fef841b401 2020-08-01 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); fef841b401 2020-08-01 kinaba: #define END verify_case(_, RoomPairs().construct(R, C, N));} fef841b401 2020-08-01 kinaba: int main(){ fef841b401 2020-08-01 kinaba: fef841b401 2020-08-01 kinaba: CASE(0) fef841b401 2020-08-01 kinaba: int R = 2; fef841b401 2020-08-01 kinaba: int C = 4; fef841b401 2020-08-01 kinaba: int N = 1; fef841b401 2020-08-01 kinaba: string __[] = {"+-+-+-+-+", "| | | |", "+ + +-+ +", "| | |", "+-+-+-+-+" }; fef841b401 2020-08-01 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); fef841b401 2020-08-01 kinaba: END fef841b401 2020-08-01 kinaba: CASE(1) fef841b401 2020-08-01 kinaba: int R = 3; fef841b401 2020-08-01 kinaba: int C = 3; fef841b401 2020-08-01 kinaba: int N = 4; fef841b401 2020-08-01 kinaba: string __[] = {"+-+-+-+", "| | | |", "+-+ +-+", "| |", "+-+ +-+", "| | | |", "+-+-+-+" }; fef841b401 2020-08-01 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); fef841b401 2020-08-01 kinaba: END fef841b401 2020-08-01 kinaba: CASE(2) fef841b401 2020-08-01 kinaba: int R = 3; fef841b401 2020-08-01 kinaba: int C = 4; fef841b401 2020-08-01 kinaba: int N = 3; fef841b401 2020-08-01 kinaba: string __[] = {"+-+-+-+-+", "| |", "+ +-+-+ +", "| | | | |", "+ +-+-+ +", "| |", "+-+-+-+-+" }; fef841b401 2020-08-01 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); fef841b401 2020-08-01 kinaba: END fef841b401 2020-08-01 kinaba: CASE(3) fef841b401 2020-08-01 kinaba: int R = 4; fef841b401 2020-08-01 kinaba: int C = 5; fef841b401 2020-08-01 kinaba: int N = 31; fef841b401 2020-08-01 kinaba: string __[] = {"+-+-+-+-+-+", "| | | | | |", "+-+-+-+-+-+", "| | | | | |", "+-+-+-+-+-+", "| | | | | |", "+-+-+-+-+-+", "| | | | | |", "+-+-+-+-+-+" }; fef841b401 2020-08-01 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); fef841b401 2020-08-01 kinaba: END fef841b401 2020-08-01 kinaba: CASE(4) fef841b401 2020-08-01 kinaba: int R = 1; fef841b401 2020-08-01 kinaba: int C = 10; fef841b401 2020-08-01 kinaba: int N = 4; fef841b401 2020-08-01 kinaba: string __[] = { "!!" }; fef841b401 2020-08-01 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); fef841b401 2020-08-01 kinaba: END fef841b401 2020-08-01 kinaba: /* fef841b401 2020-08-01 kinaba: CASE(5) fef841b401 2020-08-01 kinaba: int R = ; fef841b401 2020-08-01 kinaba: int C = ; fef841b401 2020-08-01 kinaba: int N = ; fef841b401 2020-08-01 kinaba: string __[] = { "!!" }; fef841b401 2020-08-01 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); fef841b401 2020-08-01 kinaba: END fef841b401 2020-08-01 kinaba: */ fef841b401 2020-08-01 kinaba: } fef841b401 2020-08-01 kinaba: // END CUT HERE