Submission #54097

# Submission time Handle Problem Language Result Execution time Memory
54097 2018-07-02T10:25:52 Z egorlifar Chessboard (IZhO18_chessboard) C++17
100 / 100
737 ms 89032 KB
/*
ЗАПУСКАЕМ 
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░ 
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <deque>
    
     
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } 
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define next next228
#define rank rank228
#define prev prev228
#define y1 y1228                                                         
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define x first
#define y second
const string FILENAME = "input";
const int MAXN = 100228;

//11:50
//16:50
int n, k;
int x1[MAXN], y1[MAXN], x2[MAXN], y2[MAXN];
long long ans = 1e18;


long long get(int t, int posx, int len, int yl, int yr, int x) {
    long long res = 0;
    int ly = yl / x;
    int ry = yr / x;
    if (ly == ry) {
        if ((ly + posx) % 2 == t) {
            res += 1LL * len * (yr - yl + 1);
        } else {
            res -= 1LL * len * (yr - yl + 1);
        }
    } else {
      //  exit(1);
        if (yl % x != 0) {
            if ((posx + ly) % 2 == t) {
                res += 1LL * len * (x - yl % x);
            } else {
                res -= 1LL * len * (x - yl % x);
            }
            ly++;
        }
        if (yr % x != x - 1) {
            if ((posx + ry) % 2 == t) {
                res += 1LL * len * (yr % x + 1);
            } else {
                res -= 1LL * len * (yr % x + 1);
            }
            ry--;
        }
        if (ly <= ry) {
            if ((posx + ly) % 2 == t) {
                if ((ry - ly + 1) % 2) {
                    res += 1LL * len * x;
                }
            } else {
                if ((ry - ly + 1) % 2) {
                    res -= 1LL * len * x;
                }
            }
        }
    }
    return res;
}


long long check(int t, int x) {
    long long res = 0;
    if (t == 1) {
        res += 1LL * (1LL * (n / x) * (n / x) + 1) / 2 * x * x;
    } else {
        res += 1LL * (1LL * (n / x) * (n / x) ) / 2 * x * x;
    }
   // cout << res << endl;
    for (int i = 0; i < k; i++) {
        int lx = x1[i] / x;
        int rx = x2[i] / x;
        int ly = y1[i] / x;
        int ry = y2[i] / x;
        if (lx == rx) {
            res += get(t, lx, x2[i] - x1[i] + 1, y1[i], y2[i], x);
            continue;
        }
       // exit(1);
        if (x1[i] % x != 0) {
            res += get(t, lx, x - x1[i] % x, y1[i], y2[i], x);
            lx++;
        }
        if (x2[i] % x != x - 1) {
            res += get(t, rx, x2[i] % x + 1, y1[i], y2[i], x);
            rx--;
        }
        if (lx <= rx) {
            if ((rx - lx + 1) % 2 == 1) {
                res += get(t, lx, x, y1[i], y2[i], x);
            }
        }
    }
    return res;
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//read(FILENAME);
    cin >> n >> k;
    for (int i = 0; i < k; i++) {
        cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
        x1[i]--;
        y1[i]--;
        x2[i]--;
        y2[i]--;
    }
    for (int i = 1; i < n; i++) {
        if (n % i == 0) {
            chkmin(ans, check(0, i));
            chkmin(ans, check(1, i));
        }
    }
    cout << ans << '\n';
}

Compilation message

chessboard.cpp: In function 'long long int check(int, int)':
chessboard.cpp:134:13: warning: unused variable 'ly' [-Wunused-variable]
         int ly = y1[i] / x;
             ^~
chessboard.cpp:135:13: warning: unused variable 'ry' [-Wunused-variable]
         int ry = y2[i] / x;
             ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 548 KB Output is correct
7 Correct 2 ms 788 KB Output is correct
8 Correct 2 ms 788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 1472 KB Output is correct
2 Correct 17 ms 1472 KB Output is correct
3 Correct 20 ms 2680 KB Output is correct
4 Correct 22 ms 3668 KB Output is correct
5 Correct 26 ms 5048 KB Output is correct
6 Correct 22 ms 5460 KB Output is correct
7 Correct 6 ms 5460 KB Output is correct
8 Correct 19 ms 6480 KB Output is correct
9 Correct 47 ms 9480 KB Output is correct
10 Correct 25 ms 10020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10020 KB Output is correct
2 Correct 2 ms 10020 KB Output is correct
3 Correct 2 ms 10020 KB Output is correct
4 Correct 3 ms 10020 KB Output is correct
5 Correct 2 ms 10020 KB Output is correct
6 Correct 2 ms 10020 KB Output is correct
7 Correct 2 ms 10020 KB Output is correct
8 Correct 2 ms 10020 KB Output is correct
9 Correct 2 ms 10020 KB Output is correct
10 Correct 2 ms 10020 KB Output is correct
11 Correct 3 ms 10020 KB Output is correct
12 Correct 2 ms 10020 KB Output is correct
13 Correct 2 ms 10020 KB Output is correct
14 Correct 3 ms 10020 KB Output is correct
15 Correct 3 ms 10020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10020 KB Output is correct
2 Correct 2 ms 10020 KB Output is correct
3 Correct 2 ms 10020 KB Output is correct
4 Correct 3 ms 10020 KB Output is correct
5 Correct 2 ms 10020 KB Output is correct
6 Correct 2 ms 10020 KB Output is correct
7 Correct 2 ms 10020 KB Output is correct
8 Correct 2 ms 10020 KB Output is correct
9 Correct 2 ms 10020 KB Output is correct
10 Correct 2 ms 10020 KB Output is correct
11 Correct 3 ms 10020 KB Output is correct
12 Correct 2 ms 10020 KB Output is correct
13 Correct 2 ms 10020 KB Output is correct
14 Correct 3 ms 10020 KB Output is correct
15 Correct 3 ms 10020 KB Output is correct
16 Correct 14 ms 10020 KB Output is correct
17 Correct 32 ms 10568 KB Output is correct
18 Correct 45 ms 10784 KB Output is correct
19 Correct 127 ms 10824 KB Output is correct
20 Correct 132 ms 10860 KB Output is correct
21 Correct 32 ms 10860 KB Output is correct
22 Correct 2 ms 10860 KB Output is correct
23 Correct 27 ms 10860 KB Output is correct
24 Correct 41 ms 10860 KB Output is correct
25 Correct 7 ms 10860 KB Output is correct
26 Correct 27 ms 10860 KB Output is correct
27 Correct 37 ms 10860 KB Output is correct
28 Correct 45 ms 10860 KB Output is correct
29 Correct 15 ms 10860 KB Output is correct
30 Correct 3 ms 10860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 1472 KB Output is correct
2 Correct 17 ms 1472 KB Output is correct
3 Correct 20 ms 2680 KB Output is correct
4 Correct 22 ms 3668 KB Output is correct
5 Correct 26 ms 5048 KB Output is correct
6 Correct 22 ms 5460 KB Output is correct
7 Correct 6 ms 5460 KB Output is correct
8 Correct 19 ms 6480 KB Output is correct
9 Correct 47 ms 9480 KB Output is correct
10 Correct 25 ms 10020 KB Output is correct
11 Correct 2 ms 10020 KB Output is correct
12 Correct 2 ms 10020 KB Output is correct
13 Correct 2 ms 10020 KB Output is correct
14 Correct 3 ms 10020 KB Output is correct
15 Correct 2 ms 10020 KB Output is correct
16 Correct 2 ms 10020 KB Output is correct
17 Correct 2 ms 10020 KB Output is correct
18 Correct 2 ms 10020 KB Output is correct
19 Correct 2 ms 10020 KB Output is correct
20 Correct 2 ms 10020 KB Output is correct
21 Correct 3 ms 10020 KB Output is correct
22 Correct 2 ms 10020 KB Output is correct
23 Correct 2 ms 10020 KB Output is correct
24 Correct 3 ms 10020 KB Output is correct
25 Correct 3 ms 10020 KB Output is correct
26 Correct 14 ms 10020 KB Output is correct
27 Correct 32 ms 10568 KB Output is correct
28 Correct 45 ms 10784 KB Output is correct
29 Correct 127 ms 10824 KB Output is correct
30 Correct 132 ms 10860 KB Output is correct
31 Correct 32 ms 10860 KB Output is correct
32 Correct 2 ms 10860 KB Output is correct
33 Correct 27 ms 10860 KB Output is correct
34 Correct 41 ms 10860 KB Output is correct
35 Correct 7 ms 10860 KB Output is correct
36 Correct 27 ms 10860 KB Output is correct
37 Correct 37 ms 10860 KB Output is correct
38 Correct 45 ms 10860 KB Output is correct
39 Correct 15 ms 10860 KB Output is correct
40 Correct 3 ms 10860 KB Output is correct
41 Correct 135 ms 12592 KB Output is correct
42 Correct 51 ms 14988 KB Output is correct
43 Correct 69 ms 16948 KB Output is correct
44 Correct 64 ms 19128 KB Output is correct
45 Correct 47 ms 21568 KB Output is correct
46 Correct 132 ms 23852 KB Output is correct
47 Correct 41 ms 25776 KB Output is correct
48 Correct 60 ms 27840 KB Output is correct
49 Correct 51 ms 29760 KB Output is correct
50 Correct 490 ms 32024 KB Output is correct
51 Correct 570 ms 34528 KB Output is correct
52 Correct 535 ms 36708 KB Output is correct
53 Correct 509 ms 38860 KB Output is correct
54 Correct 462 ms 41028 KB Output is correct
55 Correct 530 ms 43424 KB Output is correct
56 Correct 516 ms 45400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 540 KB Output is correct
6 Correct 2 ms 548 KB Output is correct
7 Correct 2 ms 788 KB Output is correct
8 Correct 2 ms 788 KB Output is correct
9 Correct 34 ms 1472 KB Output is correct
10 Correct 17 ms 1472 KB Output is correct
11 Correct 20 ms 2680 KB Output is correct
12 Correct 22 ms 3668 KB Output is correct
13 Correct 26 ms 5048 KB Output is correct
14 Correct 22 ms 5460 KB Output is correct
15 Correct 6 ms 5460 KB Output is correct
16 Correct 19 ms 6480 KB Output is correct
17 Correct 47 ms 9480 KB Output is correct
18 Correct 25 ms 10020 KB Output is correct
19 Correct 2 ms 10020 KB Output is correct
20 Correct 2 ms 10020 KB Output is correct
21 Correct 2 ms 10020 KB Output is correct
22 Correct 3 ms 10020 KB Output is correct
23 Correct 2 ms 10020 KB Output is correct
24 Correct 2 ms 10020 KB Output is correct
25 Correct 2 ms 10020 KB Output is correct
26 Correct 2 ms 10020 KB Output is correct
27 Correct 2 ms 10020 KB Output is correct
28 Correct 2 ms 10020 KB Output is correct
29 Correct 3 ms 10020 KB Output is correct
30 Correct 2 ms 10020 KB Output is correct
31 Correct 2 ms 10020 KB Output is correct
32 Correct 3 ms 10020 KB Output is correct
33 Correct 3 ms 10020 KB Output is correct
34 Correct 14 ms 10020 KB Output is correct
35 Correct 32 ms 10568 KB Output is correct
36 Correct 45 ms 10784 KB Output is correct
37 Correct 127 ms 10824 KB Output is correct
38 Correct 132 ms 10860 KB Output is correct
39 Correct 32 ms 10860 KB Output is correct
40 Correct 2 ms 10860 KB Output is correct
41 Correct 27 ms 10860 KB Output is correct
42 Correct 41 ms 10860 KB Output is correct
43 Correct 7 ms 10860 KB Output is correct
44 Correct 27 ms 10860 KB Output is correct
45 Correct 37 ms 10860 KB Output is correct
46 Correct 45 ms 10860 KB Output is correct
47 Correct 15 ms 10860 KB Output is correct
48 Correct 3 ms 10860 KB Output is correct
49 Correct 135 ms 12592 KB Output is correct
50 Correct 51 ms 14988 KB Output is correct
51 Correct 69 ms 16948 KB Output is correct
52 Correct 64 ms 19128 KB Output is correct
53 Correct 47 ms 21568 KB Output is correct
54 Correct 132 ms 23852 KB Output is correct
55 Correct 41 ms 25776 KB Output is correct
56 Correct 60 ms 27840 KB Output is correct
57 Correct 51 ms 29760 KB Output is correct
58 Correct 490 ms 32024 KB Output is correct
59 Correct 570 ms 34528 KB Output is correct
60 Correct 535 ms 36708 KB Output is correct
61 Correct 509 ms 38860 KB Output is correct
62 Correct 462 ms 41028 KB Output is correct
63 Correct 530 ms 43424 KB Output is correct
64 Correct 516 ms 45400 KB Output is correct
65 Correct 3 ms 45400 KB Output is correct
66 Correct 2 ms 45400 KB Output is correct
67 Correct 737 ms 47848 KB Output is correct
68 Correct 683 ms 49964 KB Output is correct
69 Correct 597 ms 51776 KB Output is correct
70 Correct 650 ms 54180 KB Output is correct
71 Correct 625 ms 56204 KB Output is correct
72 Correct 664 ms 58376 KB Output is correct
73 Correct 650 ms 60324 KB Output is correct
74 Correct 687 ms 62672 KB Output is correct
75 Correct 637 ms 64664 KB Output is correct
76 Correct 690 ms 66984 KB Output is correct
77 Correct 132 ms 69392 KB Output is correct
78 Correct 55 ms 71416 KB Output is correct
79 Correct 97 ms 73316 KB Output is correct
80 Correct 99 ms 75460 KB Output is correct
81 Correct 94 ms 77356 KB Output is correct
82 Correct 84 ms 79764 KB Output is correct
83 Correct 79 ms 81676 KB Output is correct
84 Correct 424 ms 84396 KB Output is correct
85 Correct 702 ms 86748 KB Output is correct
86 Correct 3 ms 86748 KB Output is correct
87 Correct 2 ms 86748 KB Output is correct
88 Correct 717 ms 89032 KB Output is correct
89 Correct 148 ms 89032 KB Output is correct
90 Correct 3 ms 89032 KB Output is correct