Submission #689617

# Submission time Handle Problem Language Result Execution time Memory
689617 2023-01-28T23:00:23 Z YENGOYAN Chessboard (IZhO18_chessboard) C++17
70 / 100
617 ms 4184 KB
/*
        //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
        \\                                    //
        //  271828___182845__904523__53602__  \\
        \\  87___47____13______52____66__24_  //
        //  97___75____72______47____09___36  \\
        \\  999595_____74______96____69___67  //
        //  62___77____24______07____66__30_  \\
        \\  35___35____47______59____45713__  //
        //                                    \\
        \\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
                                                    */

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>

using namespace std;
using ll = long long;
const int N = 3e5 + 5;
const ll mod = 1e9 + 7, inf = 1e18;

struct rec {
    ll x1, y1, x2, y2;
};

bool ev_od(ll x, ll y, ll side) {
    ll xx = (x + side - 1) / side, yy = (y + side - 1) / side;
    if (xx % 2 == yy % 2) return 0;
    return 1;
}

void solve() {
    ll n, k; cin >> n >> k;
    vector<rec> v(k);
    for (int i = 0; i < k; ++i) {
        cin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;
    }
    ll ans = n * n;
    for (int i = 1; i < n; ++i) {
        if (n % i) continue;
        ll od = 0, ev = 0;
        for (rec& j : v) {
            // (j.x2 - j.x1 + 1) X (j.y2 - j.y1 + 1)
            ll len_x = j.x2 - j.x1 + 1, len_y = j.y2 - j.y1 + 1;
            ll toshni_x = len_x / i * i, toshni_y = len_y / i * i;
            if (ev_od(j.x1, j.y1, i)) {
                //cout << "TAMAMA?\n";
                ll obshi = toshni_x / i * toshni_y / i;
                od += (obshi + 1) / 2 * i * i;
                ev += obshi / 2 * i * i;
                //cout << obshi << "\n";
            }
            else {
                //cout << "TAMAMA?\n";
                ll obshi = toshni_x / i * toshni_y / i;
                od += obshi / 2 * i * i;
                ev += (obshi + 1) / 2 * i * i;
                //cout << obshi << "\n";
            }
            //cout << od << " " << ev << "\n";
            //break;
            ll new_x = j.x1 + toshni_x - 1, new_y = j.y1 + toshni_y - 1;
            //cout << new_x << " " << new_y << "\n";
            ll w = j.x2 - new_x, h = new_y - j.y1;
            ll c = h / i;
            if (ev_od(new_x + 1, j.y1, i)) {
                od += (c + 1) / 2 * w * i;
                ev += c / 2 * w * i;
            }
            else {
                od += c / 2 * w * i;
                ev += (c + 1) / 2 * w * i;
            }
            h = j.y2 - new_y, w = new_x - j.x1;
            c = w / i;
            if (ev_od(j.x1, new_y + 1, i)) {
                od += (c + 1) / 2 * h * i;
                ev += c / 2 * h * i;
            }
            else {
                od += c / 2 * h * i;
                ev += (c + 1) / 2 * h * i;
            }
            if (ev_od(new_x + 1, new_y + 1, i)) {
                od += (j.x2 - new_x) * (j.y2 - new_y);
            }
            else {
                ev += (j.x2 - new_x) * (j.y2 - new_y);
            }
            //cout << od << " " << ev << "\n";

        }
        /*ll edge = n / i, c = (edge * edge + 1) / 2;
        ll a = od + c * i * i - ev;
        c = edge * edge / 2;
        ll b = ev + c * i * i - od;
        cout << a << " " << b << " ";
        ans = min({ ans, a, b });*/
        //swap(ev, od);
        //cout << od << " " << ev << "\n";
        ll edge = n / i;
        ll yndhanur_zuyg = (edge * edge + 1) / 2 * i * i, yndhanur_kent = (edge * edge) / 2 * i * i;
        //cout << od << " " << ev << "\n";
        //cout << yndhanur_kent << " " << yndhanur_zuyg << "\n";
        ll bl = yndhanur_zuyg - ev + od;
        ans = min(ans, bl);
        ll wh = yndhanur_kent - od + ev;
        ans = min(ans, wh);
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    //int t; cin >> t;
    //while (t--)	
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2760 KB Output is correct
2 Correct 7 ms 1028 KB Output is correct
3 Correct 15 ms 1704 KB Output is correct
4 Correct 17 ms 1996 KB Output is correct
5 Correct 19 ms 2252 KB Output is correct
6 Correct 13 ms 1588 KB Output is correct
7 Correct 3 ms 636 KB Output is correct
8 Correct 14 ms 1612 KB Output is correct
9 Correct 32 ms 3556 KB Output is correct
10 Correct 19 ms 2104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 328 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 324 KB Output is correct
16 Correct 11 ms 1492 KB Output is correct
17 Correct 26 ms 3660 KB Output is correct
18 Correct 38 ms 4080 KB Output is correct
19 Correct 134 ms 3752 KB Output is correct
20 Correct 149 ms 4172 KB Output is correct
21 Correct 25 ms 3500 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 25 ms 2000 KB Output is correct
24 Correct 35 ms 3812 KB Output is correct
25 Correct 6 ms 724 KB Output is correct
26 Correct 22 ms 2564 KB Output is correct
27 Correct 33 ms 3104 KB Output is correct
28 Correct 36 ms 3992 KB Output is correct
29 Correct 10 ms 1636 KB Output is correct
30 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2760 KB Output is correct
2 Correct 7 ms 1028 KB Output is correct
3 Correct 15 ms 1704 KB Output is correct
4 Correct 17 ms 1996 KB Output is correct
5 Correct 19 ms 2252 KB Output is correct
6 Correct 13 ms 1588 KB Output is correct
7 Correct 3 ms 636 KB Output is correct
8 Correct 14 ms 1612 KB Output is correct
9 Correct 32 ms 3556 KB Output is correct
10 Correct 19 ms 2104 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 328 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 324 KB Output is correct
26 Correct 11 ms 1492 KB Output is correct
27 Correct 26 ms 3660 KB Output is correct
28 Correct 38 ms 4080 KB Output is correct
29 Correct 134 ms 3752 KB Output is correct
30 Correct 149 ms 4172 KB Output is correct
31 Correct 25 ms 3500 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 25 ms 2000 KB Output is correct
34 Correct 35 ms 3812 KB Output is correct
35 Correct 6 ms 724 KB Output is correct
36 Correct 22 ms 2564 KB Output is correct
37 Correct 33 ms 3104 KB Output is correct
38 Correct 36 ms 3992 KB Output is correct
39 Correct 10 ms 1636 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 114 ms 3556 KB Output is correct
42 Correct 47 ms 4004 KB Output is correct
43 Correct 79 ms 3788 KB Output is correct
44 Correct 40 ms 3824 KB Output is correct
45 Correct 33 ms 4044 KB Output is correct
46 Correct 132 ms 3956 KB Output is correct
47 Correct 30 ms 3680 KB Output is correct
48 Correct 66 ms 3768 KB Output is correct
49 Correct 51 ms 3656 KB Output is correct
50 Correct 560 ms 3916 KB Output is correct
51 Correct 605 ms 4072 KB Output is correct
52 Correct 587 ms 3788 KB Output is correct
53 Correct 617 ms 3984 KB Output is correct
54 Correct 552 ms 3824 KB Output is correct
55 Correct 609 ms 4184 KB Output is correct
56 Correct 546 ms 3788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 23 ms 2760 KB Output is correct
10 Correct 7 ms 1028 KB Output is correct
11 Correct 15 ms 1704 KB Output is correct
12 Correct 17 ms 1996 KB Output is correct
13 Correct 19 ms 2252 KB Output is correct
14 Correct 13 ms 1588 KB Output is correct
15 Correct 3 ms 636 KB Output is correct
16 Correct 14 ms 1612 KB Output is correct
17 Correct 32 ms 3556 KB Output is correct
18 Correct 19 ms 2104 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 324 KB Output is correct
31 Correct 1 ms 328 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 324 KB Output is correct
34 Correct 11 ms 1492 KB Output is correct
35 Correct 26 ms 3660 KB Output is correct
36 Correct 38 ms 4080 KB Output is correct
37 Correct 134 ms 3752 KB Output is correct
38 Correct 149 ms 4172 KB Output is correct
39 Correct 25 ms 3500 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 25 ms 2000 KB Output is correct
42 Correct 35 ms 3812 KB Output is correct
43 Correct 6 ms 724 KB Output is correct
44 Correct 22 ms 2564 KB Output is correct
45 Correct 33 ms 3104 KB Output is correct
46 Correct 36 ms 3992 KB Output is correct
47 Correct 10 ms 1636 KB Output is correct
48 Correct 2 ms 340 KB Output is correct
49 Correct 114 ms 3556 KB Output is correct
50 Correct 47 ms 4004 KB Output is correct
51 Correct 79 ms 3788 KB Output is correct
52 Correct 40 ms 3824 KB Output is correct
53 Correct 33 ms 4044 KB Output is correct
54 Correct 132 ms 3956 KB Output is correct
55 Correct 30 ms 3680 KB Output is correct
56 Correct 66 ms 3768 KB Output is correct
57 Correct 51 ms 3656 KB Output is correct
58 Correct 560 ms 3916 KB Output is correct
59 Correct 605 ms 4072 KB Output is correct
60 Correct 587 ms 3788 KB Output is correct
61 Correct 617 ms 3984 KB Output is correct
62 Correct 552 ms 3824 KB Output is correct
63 Correct 609 ms 4184 KB Output is correct
64 Correct 546 ms 3788 KB Output is correct
65 Correct 0 ms 212 KB Output is correct
66 Incorrect 1 ms 212 KB Output isn't correct
67 Halted 0 ms 0 KB -