Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int, int>
- #define pb(x) push_back(x)
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvl(vector <ll> &v) {
- for (auto x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvv(vector <vector <int> > &v) {
- for (auto x : v) cv(x);
- cout << "\n";
- }
- void cvb(vector <bool> v) {
- for (bool x : v) cout << x << ' ';
- cout << "\n";
- }
- void cvs(vector <string> v) {
- for (auto a : v) {
- cout << a << "\n";
- }
- }
- void cvp(vector <pii> a) {
- for (auto p : a) {
- cout << p.first << ' ' << p.second << "\n";
- }
- cout << "\n";
- }
- ll S(ll a1, ll n) {
- return (2 * a1 + n - 1) * n / 2;
- }
- ll n, m;
- ll frx, tox, fry, toy;
- bool ok(int i, int j) {
- return i >= frx && i <= tox && j >= fry && j <= toy;
- }
- vector <int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
- bool sh = 0;
- int main() {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- cin >> n >> m;
- frx = -2;
- tox = n - 1;
- fry = 0;
- toy = m - 1;
- ll cnt = 1;
- vector <vector <int> > a(n, vector <int> (m, 0));
- if (min(n, m) == 1) {
- cout << n * m;
- exit(0);
- }
- a[0][0] = 1;
- int i = 0, j = 0, to = 0;
- while (1) {
- //cnt +=
- while ( ok(i + dx[to], j + dy[to]) ) {
- i += dx[to];
- j += dy[to];
- a[i][j] = 1;
- cnt++;
- }
- if (sh) {
- cout << "to = " << to << "\n";
- cout << "frx tox = " << frx << ' ' << tox << "\n";
- cout << "fry toy = " << fry << ' ' << toy << "\n";
- }
- if (to == 0) {
- frx += 2;
- //tox -= 2;
- }
- else if (to == 2) {
- tox -= 2;
- }
- else if (to == 1) {
- fry += 2;
- }
- else if (to == 3) {
- toy -= 2;
- }
- to++;
- to %= 4;
- if (sh) {
- cout << "to = " << to << "\n";
- cout << "i + dx[to] j + dy[to] = " << i + dx[to] << ' ' << j + dy[to] << "\n";
- }
- if (!ok(i + dx[to], j + dy[to])) {
- break;
- }
- }
- if (sh) {
- cout << "i j = " << i << ' ' << j << "\n";
- cout << "to = " << to << "\n";
- cout << "ans\n";
- }
- cout << cnt << "\n";
- if (sh) {
- cvv(a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement