Advertisement
999ms

mamku ebal

Sep 10th, 2020
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.65 KB | None | 0 0
  1. TASK A
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5.  
  6. string hsh(string s) {
  7. char start = s[0];
  8. for (char& ch : s) {
  9. ch -= start;
  10. if (ch < 0) ch += 26;
  11. }
  12. return s;
  13. }
  14.  
  15. int main(){
  16. ios::sync_with_stdio(false);
  17. cin.tie(nullptr);
  18. cout.tie(nullptr);
  19. string full;
  20. getline(cin, full);
  21. int pre = 0;
  22. map<string, string> mp;
  23. for (int i = 0; i <= full.size(); i++) {
  24. if (full[i] == ' ' || i == full.size()) {
  25. string current;
  26. for (int j = pre; j < i; j++) {
  27. current.push_back(full[j]);
  28. }
  29. if (current.size())
  30. mp[hsh(current)] = current;
  31. pre = i + 1;
  32. }
  33. }
  34. int q;
  35. string sq;
  36. getline(cin, sq);
  37. q = stoi(sq);
  38. while (q--) {
  39. string s;
  40. getline(cin, s);
  41. cout << mp[hsh(s)] << '\n';
  42. }
  43. }
  44. /////////////////////////////////
  45.  
  46. TASK B
  47. #include<bits/stdc++.h>
  48. #define all(x) begin(x),end(x)
  49.  
  50. using namespace std;
  51.  
  52. int main(){
  53. ios::sync_with_stdio(false);
  54. cin.tie(nullptr);
  55. cout.tie(nullptr);
  56. int n;
  57. cin >> n;
  58. vector<pair<int,int>> arr(n);
  59. for (auto& [a, b] : arr) {
  60. cin >> a >> b;
  61. if (a > b) swap(a, b);
  62. }
  63. sort(all(arr));
  64. vector<int> mx(n);
  65. for (int i = n - 1; i >= 0; i--) {
  66. mx[i] = arr[i].second;
  67. if (i + 1 < n) {
  68. mx[i] = max(mx[i], mx[i + 1]);
  69. }
  70. }
  71. int lst = 0;
  72. int ans = 1;
  73. for (int i = n - 2; i >= 0; i--) {
  74. if (arr[i].first != arr[i + 1].first) {
  75. lst = max(lst, mx[i + 1]);
  76. }
  77. if (lst <= arr[i].second) {
  78. ans++;
  79. }
  80. }
  81. cout << ans << '\n';
  82. }
  83. ////////////////////////
  84.  
  85. TASK C
  86. #include<bits/stdc++.h>
  87.  
  88. #define endl "\n"
  89. using namespace std;
  90. using ll = long long;
  91. using ld = long double;
  92. using pii = pair<int, int>;
  93.  
  94. constexpr ld eps = 1e-9;
  95.  
  96. int n[2], c1 = INT32_MIN, c2 = INT32_MIN, le = INT32_MIN;
  97. vector<tuple<int, int, bool>> vec[2], events;
  98. vector<tuple<int, int, int>> coefs[2];
  99. ld ans = 0;
  100.  
  101. ld t(ld x) {
  102. return x * x * x;
  103. }
  104.  
  105. ld s(ld x) {
  106. return x * x;
  107. }
  108.  
  109. ld func(ld a, ld b, ld c, ld l, ld r) {
  110. if (r - l < eps)
  111. return 0;
  112. return abs(a / 3 * (t(r) - t(l)) +
  113. b / 2 * (s(r) - s(l)) +
  114. c * (r - l));
  115. }
  116.  
  117. ld get_ans(tuple<ld, ld, ld> a, tuple<ld, ld, ld> b, ld l, ld r) {
  118. auto [a1, b1, c1] = a;
  119. auto [a2, b2, c2] = b;
  120. a1 -= a2, b1 -= b2, c1 -= c2;
  121. if (abs(a1) < eps) {
  122. if (abs(b1) < eps) {
  123. return func(a1, b1, c1, l, r);
  124. }
  125. ld x1 = -c1 / b1;
  126. return
  127. func(0, b1, c1, l, min(x1, r)) +
  128. func(0, b1, c1, max(l, x1), r);
  129. }
  130. ld disc = b1 * b1 - a1 * c1 * 4;
  131. if (disc < eps) {
  132. return func(a1, b1, c1, l, r);
  133. }
  134. else {
  135. ld x1 = (-b1 - sqrtl(disc)) / (2 * a1);
  136. ld x2 = (-b1 + sqrtl(disc)) / (2 * a1);
  137. if (x1 > x2)
  138. swap(x1, x2);
  139. return
  140. func(a1, b1, c1, l, min(x1, r)) +
  141. func(a1, b1, c1, max(l, x1), min(x2, r)) +
  142. func(a1, b1, c1, max(l, x2), r);
  143. }
  144. }
  145.  
  146. void Solve() {
  147. for (int i = 0; i < 2; i++)
  148. cin >> n[i];
  149. for (int i = 0; i < 2; i++) {
  150. for (int j = 0, v; j <= n[i]; j++) {
  151. cin >> v;
  152. vec[i].emplace_back(v, j, i);
  153. }
  154. for (int j = 0, a, b, c; j < n[i]; j++) {
  155. cin >> a >> b >> c;
  156. coefs[i].emplace_back(a, b, c);
  157. }
  158. }
  159. merge(vec[0].begin(), vec[0].end(),
  160. vec[1].begin(), vec[1].end(),
  161. back_inserter(events));
  162. for (auto [d, id, i]: events) {
  163. if (c1 != INT32_MIN && c2 != INT32_MIN && le != INT32_MIN) {
  164. ans += get_ans(coefs[0][c1], coefs[1][c2], le, d);
  165. le = d;
  166. if (i)
  167. c2 = id;
  168. else
  169. c1 = id;
  170. }
  171. else if (i) {
  172. le = d;
  173. c2 = id;
  174. }
  175. else {
  176. le = d;
  177. c1 = id;
  178. }
  179. }
  180. cout << fixed << setprecision(10) << ans;
  181. }
  182.  
  183. int main(){
  184. ios::sync_with_stdio(false);
  185. cin.tie(nullptr);
  186. cout.tie(nullptr);
  187. //auto start = chrono::high_resolution_clock::now();
  188. Solve();
  189. //auto end = chrono::high_resolution_clock::now();
  190. //cout << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
  191. return 0;
  192. }
  193. ///////////////////////
  194.  
  195. TASK D
  196. #pragma GCC Optimaze("Ofast")
  197. #pragma GCC target("avx")
  198.  
  199. #include<bits/stdc++.h>
  200. #define all(x) begin(x),end(x)
  201.  
  202. using namespace std;
  203. using ll = long long;
  204.  
  205. const int mod = 1e9 + 7;
  206.  
  207. int dp[2][51][51][251];
  208. const ll N = 1e5;
  209.  
  210. ll fact[N];
  211. ll invfact[N];
  212.  
  213. ll fpow(ll a, ll p) {
  214. ll ans = 1;
  215. while (p) {
  216. if (p & 1) {
  217. ans = (ans * a) % mod;
  218. }
  219. a = (a * a) % mod;
  220. p >>= 1;
  221. }
  222. return ans;
  223. }
  224.  
  225. ll rev(ll a) {
  226. return fpow(a, mod - 2);
  227. }
  228.  
  229. void init() {
  230. fact[0] = 1;
  231. invfact[0] = 1;
  232. for (int i = 1; i < N; i++) {
  233. fact[i] = fact[i - 1] * i % mod;
  234. invfact[i] = rev(fact[i]);
  235. }
  236. }
  237.  
  238. ll precalc[1000][1000];
  239.  
  240. ll C(int n, int m) {
  241. if (n < m) return 0;
  242. return precalc[n][m] = (fact[n] * invfact[m] % mod) * invfact[n - m] % mod;
  243. }
  244.  
  245. ll C2(int n, int m) {
  246. if (n < m) return 0;
  247. return precalc[n][m];
  248. }
  249.  
  250. int main(){
  251. ios::sync_with_stdio(false);
  252. cin.tie(nullptr);
  253. cout.tie(nullptr);
  254. init();
  255. int n;
  256.  
  257. for (int i = 0; i < 1000; i++) {
  258. for (int j = 0; j < 1000; j++) {
  259. precalc[i][j] = C(i, j);
  260. }
  261. }
  262.  
  263. cin >> n;
  264. vector<int> a(n);
  265. for (int i = 0; i < n; i++) cin >> a[i];
  266. sort(all(a));
  267. int cnt = accumulate(all(a), 0);
  268. dp[1][0][0][0] = 1;
  269.  
  270. int sum = 0;
  271.  
  272. for (int x = 0; x < n; x++) {
  273. int ni = x & 1;
  274. int pi = ni ^ 1;
  275.  
  276. for (int cnt = 1; cnt < a[x]; cnt++) {
  277. for (int first_has = 0; first_has <= sum && first_has + cnt <= 250; first_has++) {
  278. ll coef = C2(first_has + cnt, cnt) * C2(sum - first_has + a[x] - cnt, a[x] - cnt) % mod;
  279. if (coef) {
  280. #pragma GCC ivdep
  281. for (int i = 0; i <= x; i++) {
  282. for (int j = 0; j <= x; j++) {
  283. dp[ni][i + 1][j + 1][first_has + cnt] = (dp[ni][i + 1][j + 1][first_has + cnt] + dp[pi][i][j][first_has] * coef) % mod;
  284. }
  285. }
  286. }
  287. }
  288. }
  289.  
  290. for (int first_has = 0; first_has <= 250; first_has++) {
  291. for (int i = 0; i <= x; i++) {
  292. for (int j = 0; j <= x; j++) {
  293. dp[ni][i + 1][j][first_has + a[x]] = (dp[ni][i + 1][j][first_has + a[x]] + dp[pi][i][j][first_has] * C2(first_has + a[x], a[x])) % mod;
  294. dp[ni][i][j + 1][first_has] = (dp[ni][i][j + 1][first_has] + dp[pi][i][j][first_has] * C2(sum - first_has + a[x], a[x])) % mod;
  295. }
  296. }
  297. }
  298.  
  299. for (int i = 0; i <= 50; i++) {
  300. for (int j = 0; j <= 50; j++) {
  301. for (int k = 0; k <= 250; k++) {
  302. dp[pi][i][j][k] = 0;
  303. }
  304. }
  305. }
  306.  
  307. sum += a[x];
  308. }
  309.  
  310. ll ans = 0;
  311.  
  312. for (int i = 0; i <= n; i++) {
  313. ans += dp[(n + 1) & 1][i][i][cnt / 2];
  314. ans %= mod;
  315. }
  316. ans *= rev(fact[cnt]);
  317. ans %= mod;
  318. for (int val : a) {
  319. ans = (ans * fact[val]) % mod;
  320. }
  321. cout << ans << '\n';
  322. }
  323. //////////////////////////////
  324.  
  325.  
  326. TASK E
  327. #include<bits/stdc++.h>
  328.  
  329. #define endl "\n"
  330. using namespace std;
  331. using ll = long long;
  332. using ld = long double;
  333. using pii = pair<int, int>;
  334.  
  335. constexpr int N = 3e5 + 5;
  336.  
  337. struct Treap {
  338. struct Node {
  339. int val;
  340. int sz;
  341. int pri;
  342. Node *l, *r;
  343. Node(int val = 0) :
  344. val(val), sz(1),
  345. pri(rand() ^ (rand() << 16)),
  346. l(nullptr), r(nullptr){};
  347. };
  348.  
  349. using pN = Node*;
  350. using pNN = pair<pN, pN>;
  351.  
  352. Node buff[N];
  353. int st = 0;
  354. pN root = nullptr;
  355.  
  356. int getsz(pN v) {
  357. return v == nullptr ? 0: v -> sz;
  358. }
  359.  
  360. int getval(pN v) {
  361. return v == nullptr ? 0 : v -> val;
  362. }
  363.  
  364. pN newN(int v) {
  365. buff[st] = Node(v);
  366. return &buff[st++];
  367. }
  368.  
  369. void recalc(pN v) {
  370. v -> sz = getsz(v -> l) + getsz(v -> r) + 1;
  371. }
  372.  
  373. pN merge(pN l, pN r) {
  374. if (l == nullptr)
  375. return r;
  376. if (r == nullptr)
  377. return l;
  378. if (l -> pri < r -> pri) {
  379. l -> r = merge(l -> r, r);
  380. recalc(l);
  381. return l;
  382. }
  383. else {
  384. r -> l = merge(l, r -> l);
  385. recalc(r);
  386. return r;
  387. }
  388. }
  389.  
  390. pNN split(pN v, int k) {
  391. if (k == 0)
  392. return {nullptr, v};
  393. if (getsz(v -> l) >= k) {
  394. auto p = split(v -> l, k);
  395. v -> l = p.second;
  396. recalc(v);
  397. return {p.first, v};
  398. }
  399. else {
  400. auto p = split(v -> r, k - getsz(v -> l) - 1);
  401. v -> r = p.first;
  402. recalc(v);
  403. return {v, p.second};
  404. }
  405. }
  406.  
  407. void insert(int pos, int val) {
  408. auto p1 = split(root, pos - 1);
  409. auto v = newN(val);
  410. root = merge(p1.first, merge(v, p1.second));
  411. return;
  412. }
  413.  
  414. void erase(int pos) {
  415. auto p1 = split(root, pos - 1);
  416. auto p2 = split(p1.second, 1);
  417. root = merge(p1.first, p2.second);
  418. return;
  419. }
  420.  
  421. int get_ans(int pos) {
  422. auto p1 = split(root, pos - 1);
  423. auto p2 = split(p1.second, 1);
  424. int ans = getval(p2.first);
  425. root = merge(merge(p2.first, p1.first), p2.second);
  426. return ans;
  427. }
  428. } tr;
  429.  
  430. struct SegTree {
  431.  
  432. vector<int> tr;
  433.  
  434. SegTree(int n) {
  435. tr.resize(n << 2);
  436. }
  437.  
  438. void upd(int pos, int val, int i, int l, int r) {
  439. if (l + 1 == r) {
  440. tr[i] += val;
  441. return;
  442. }
  443. int mid = (l + r) >> 1;
  444. if (pos < mid)
  445. upd(pos, val, (i << 1) + 1, l, mid);
  446. else
  447. upd(pos, val, (i << 1) + 2, mid, r);
  448. tr[i] = (tr[(i << 1) + 1] + tr[(i << 1) + 2]);
  449. }
  450.  
  451. int get(int l, int r, int i, int cl, int cr) {
  452. if (l >= r)
  453. return 0;
  454. if (l == cl && r == cr)
  455. return tr[i];
  456. int mid = (cl + cr) >> 1;
  457. return
  458. get(l, min(mid, r), (i << 1) + 1, cl, mid) +
  459. get(max(l, mid), r, (i << 1) + 2, mid, cr);
  460. }
  461. };
  462.  
  463. int n, m, type;
  464. vector<int> temp[N];
  465. vector<int> vec, dop;
  466.  
  467. void Solve() {
  468. cin >> n >> m >> type;
  469. if (type == 2) {
  470. for (int i = 1; i <= m; i++)
  471. tr.insert(i, i);
  472. for (int i = 0, pos; i < n; i++) {
  473. cin >> pos;
  474. int a = tr.get_ans(pos);
  475. //assert(a > 0);
  476. cout << a << " ";
  477. }
  478. }
  479. else {
  480. for (int i = 0, v; i < n; i++) {
  481. cin >> v;
  482. vec.push_back(v);
  483. }
  484. dop = vec;
  485. reverse(dop.begin(), dop.end());
  486. for (int i = 1; i <= m; i++) {
  487. dop.push_back(i);
  488. }
  489. for (int i = 0; i < dop.size(); i++) {
  490. temp[dop[i]].push_back(i);
  491. }
  492. SegTree t(dop.size());
  493. for (int i = vec.size(); i < dop.size(); i++)
  494. t.upd(i, 1, 0, 0, dop.size());
  495. for (int i: vec) {
  496. int a = t.get(0, temp[i].back() + 1, 0, 0, dop.size());
  497. assert(a > 0);
  498. cout << a << ' ';
  499. t.upd(temp[i].back(), -1, 0, 0, dop.size());
  500. temp[i].pop_back();
  501. t.upd(temp[i].back(), 1, 0, 0, dop.size());
  502. }
  503. }
  504. }
  505.  
  506. int main(){
  507. ios::sync_with_stdio(false);
  508. cin.tie(nullptr);
  509. cout.tie(nullptr);
  510. //auto start = chrono::high_resolution_clock::now();
  511. Solve();
  512. //auto end = chrono::high_resolution_clock::now();
  513. //cout << (chrono::duration_cast<chrono::duration<double>>(end - start)).count();
  514. return 0;
  515. }
  516. ///////////////////////////////////
  517.  
  518. TASK F
  519. #include<bits/stdc++.h>
  520. #define all(x) begin(x),end(x)
  521.  
  522. using namespace std;
  523. using ll = long long;
  524.  
  525. pair<ll, ll> getNum(string s) {
  526. ll a = 0, b = 0;
  527. for (int i = 0; i < int(s.size()); i++) {
  528. if (s[i] >= 'A' && s[i] <= 'Z') {
  529. a *= 26;
  530. a += s[i] - 'A' + 1;
  531. } else if (s[i] >= '0' && s[i] <= '9') {
  532. b *= 10;
  533. b += s[i] - '0';
  534. }
  535. }
  536. b--;
  537. a--;
  538. return {b, a};
  539. }
  540.  
  541. void print(vector<string>& arr, int n, int m) {
  542. for (int i = 0; i < n; i++) {
  543. for (int j = 0; j < m; j++) {
  544. if (arr[i][j] == ' ') {
  545. cout << ' ';
  546. } else {
  547. int h = (i > 0 ? arr[i - 1][j] != ' ' : 0) + (arr[i + 1][j] != ' ');
  548. int v = (j > 0 ? arr[i][j - 1] != ' ' : 0) + (arr[i][j + 1] != ' ');
  549. if (h > 0 && v > 0) {
  550. cout << '+';
  551. } else if (h > 0) {
  552. cout << '|';
  553. } else if (v > 0) {
  554. cout << '-';
  555. } else {
  556. assert(false);
  557. }
  558. }
  559. }
  560. cout << '\n';
  561. }
  562. }
  563.  
  564. vector<string> split(string s) {
  565. vector<string> res;
  566. string cur = "";
  567. for (char ch : s) {
  568. if (ch != ' ') {
  569. cur.push_back(ch);
  570. } else {
  571. if (cur.size()) {
  572. res.push_back(cur);
  573. }
  574. cur = "";
  575. }
  576. }
  577. if (cur.size()) {
  578. res.push_back(cur);
  579. }
  580. return res;
  581. }
  582.  
  583. int main(){
  584. ios::sync_with_stdio(false);
  585. cin.tie(nullptr);
  586. cout.tie(nullptr);
  587.  
  588. string nm;
  589. getline(cin, nm);
  590. vector<string> mn_arr = split(nm);
  591. int n = stoi(mn_arr[0]);
  592. int m = stoi(mn_arr[1]);
  593.  
  594. vector<string> arr(n + 1);
  595. vector<string> brr(n + 1, string(m + 1, ' '));
  596. for (int i = 0; i < n; i++) {
  597. getline(cin, arr[i]);
  598. for (int j = 0; j < m; j++) {
  599. if (arr[i][j] != ' ') arr[i][j] = 'X';
  600. if (i == 0 || i + 1 == n || j == 0 || j + 1 == m) {
  601. brr[i][j] = 'X';
  602. arr[i][j] = 'X';
  603. }
  604. }
  605. arr[i].push_back(' ');
  606. arr[i][m] = ' ';
  607. }
  608. arr.back() = brr.back();
  609.  
  610. string rows;
  611. getline(cin, rows);
  612. int row = stoi(rows);
  613.  
  614. vector<int> h(row);
  615. string hs;
  616. getline(cin, hs);
  617. auto hsv = split(hs);
  618. for (int i = 0; i < row; i++) {
  619. h[i] = stoi(hsv[i]);
  620. }
  621.  
  622. string cols;
  623. getline(cin, cols);
  624. int col = stoi(cols);
  625.  
  626. vector<int> w(col);
  627. string ws;
  628. getline(cin, ws);
  629. auto wsv = split(ws);
  630. for (int i = 0; i < col; i++) {
  631. w[i] = stoi(wsv[i]);
  632. }
  633.  
  634. {
  635. int cur = 0;
  636. for (int i = 0; i + 1 < row; i++) {
  637. cur += h[i] + 1;
  638. for (int j = 0; j < m; j++) {
  639. brr[cur][j] = 'X';
  640. }
  641. }
  642. }
  643. {
  644. int cur = 0;
  645. for (int i = 0; i + 1 < col; i++) {
  646. cur += w[i] + 1;
  647. for (int j = 0; j < n; j++) {
  648. brr[j][cur] = 'X';
  649. }
  650. }
  651. }
  652.  
  653. vector<pair<int,int>> steps = {
  654. {0, 1},
  655. {1, 0},
  656. {0, -1},
  657. {-1, 0},
  658. {1, 1},
  659. {1, -1},
  660. {-1, 1},
  661. {-1, -1}
  662. };
  663.  
  664. auto get_borders = [&] (int fx, int fy) {
  665. int mxx = fx, mxy = fy;
  666. int mnx = fx, mny = fy;
  667.  
  668. vector<vector<bool>> used(n + 1, vector<bool>(m + 1, false));
  669.  
  670. queue<pair<int,int>> q;
  671. q.emplace(fx, fy);
  672. while (q.size()) {
  673. auto [x, y] = q.front();
  674.  
  675. mxx = max(mxx, x);
  676. mnx = min(mnx, x);
  677.  
  678. mxy = max(mxy, y);
  679. mny = min(mny, y);
  680. q.pop();
  681. used[x][y] = true;
  682. for (auto& [dx, dy] : steps) {
  683. int nx = dx + x;
  684. int ny = dy + y;
  685. if (nx < 0 || ny < 0 || nx >= n || ny >= m) continue;
  686. if (arr[nx][ny] != ' ') continue;
  687. if (used[nx][ny]) continue;
  688. used[nx][ny] = true;
  689. q.emplace(nx, ny);
  690. }
  691. }
  692. return pair<pair<int,int>, pair<int,int>> ({mnx - 1, mny - 1}, {mxx + 1, mxy + 1});
  693. };
  694.  
  695. auto get_pos_by_cell = [&] (int x, int y) {
  696. int rx = 1;
  697. int ry = 1;
  698. for (int i = 0; i < x; i++) {
  699. rx += h[i] + 1;
  700. }
  701. for (int i = 0; i < y; i++) {
  702. ry += w[i] + 1;
  703. }
  704. return pair<int,int>(rx, ry);
  705. };
  706.  
  707.  
  708. string qs;
  709. getline(cin, qs);
  710. int q = stoi(qs);
  711. while (q--) {
  712. string inp;
  713. getline(cin, inp);
  714. auto vec = split(inp);
  715.  
  716. string type = vec[0];
  717. if (type == "merge") {
  718. string a = vec[1], b = vec[2];
  719. auto [cx1, cy1] = getNum(a);
  720. auto [x1, y1] = get_pos_by_cell(cx1, cy1);
  721. auto [cx2, cy2] = getNum(b);
  722. auto [x2, y2] = get_pos_by_cell(cx2, cy2);
  723.  
  724. auto [mn1, mx1] = get_borders(x1, y1);
  725. auto [mn2, mx2] = get_borders(x2, y2);
  726.  
  727. if (mn1 == mn2 && mx1 == mx2) {
  728. cout << "Can not merge cell with itself\n";
  729. } else {
  730. if (mn1 > mn2) {
  731. swap(mn1, mn2);
  732. swap(mx1, mx2);
  733. }
  734.  
  735. if (mn1.first == mn2.first
  736. && mx1.first == mx2.first
  737. && mx1.second == mn2.second) {
  738. cout << "Merged horizontally-aligned cells\n";
  739. for (int x = mn1.first + 1; x < mx2.first; x++) {
  740. for (int y = mn1.second + 1; y < mx2.second; y++) {
  741. arr[x][y] = ' ';
  742. }
  743. }
  744. print(arr, n, m);
  745.  
  746. } else if (mn1.second == mn2.second
  747. && mx1.second == mx2.second
  748. && mx1.first == mn2.first) {
  749. cout << "Merged vertically-aligned cells\n";
  750. for (int x = mn1.first + 1; x < mx2.first; x++) {
  751. for (int y = mn1.second + 1; y < mx2.second; y++) {
  752. arr[x][y] = ' ';
  753. }
  754. }
  755. print(arr, n, m);
  756. } else {
  757. cout << "Can not merge unaligned cells\n";
  758. }
  759. }
  760. } else {
  761. string a = vec[1];
  762. auto [cx1, cy1] = getNum(a);
  763. auto [x1, y1] = get_pos_by_cell(cx1, cy1);
  764. auto [mn, mx] = get_borders(x1, y1);
  765. bool good = false;
  766. for (int x = mn.first + 1; x < mx.first; x++) {
  767. for (int y = mn.second + 1; y < mx.second; y++) {
  768. if (arr[x][y] == ' ' && brr[x][y] != ' ') {
  769. good = true;
  770. }
  771. arr[x][y] = brr[x][y];
  772. }
  773. }
  774.  
  775. if (good) {
  776. int hcnt = 0;
  777. int wcnt = 0;
  778.  
  779. for (int y = mn.second; y < mx.second; y++) {
  780. if (arr[mn.first + 1][y] != ' ') {
  781. hcnt++;
  782. }
  783. }
  784.  
  785. for (int x = mn.first; x < mx.first; x++) {
  786. if (arr[x][mn.second + 1] != ' ') {
  787. wcnt++;
  788. }
  789. }
  790. assert(wcnt < mx.first - mn.first);
  791. assert(hcnt < mx.second - mn.second);
  792.  
  793. ll cnt = 1ll * hcnt * wcnt;
  794. assert(cnt > 1);
  795. cout << "Split onto " << cnt << " cells\n";
  796. print(arr, n, m);
  797. } else {
  798. cout << "Can not split elementary cell\n";
  799. }
  800. }
  801. }
  802. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement