답안 #1090038

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090038 2024-09-17T15:57:57 Z MrPavlito Chessboard (IZhO18_chessboard) C++17
100 / 100
653 ms 5884 KB
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define sc second
#define endl "\n"
#define pii pair<int,int>

using namespace std;

const int MAXN = 1e5+5;
const int mod7 = 1e9+7;
const long long inf = 1e18;

struct kvadrat{int x1,y1,x2,y2;};
int n,k;
vector<kvadrat> niz;
long long rez = inf;

/// gornjelevo
int check1(int x, int y, int d)
{
    int novox = x/d * d;
    int novoy = y/d * d;
    int kvadrat1 = ((y/d) * (x/d)+1)/2 * (d*d);
    int visina = (x - novox);
    int kvadrat2;
    if(((x-1)/d+1) % 2 == 1)kvadrat2 = visina * ((novoy / d+1)/2) * d;
    else kvadrat2 = visina * ((novoy / d)/2) * d;
    int kvadrat3;
    visina = (y - novoy);
    if(((y-1)/d+1) % 2 == 1)kvadrat3 = visina * ((novox / d+1)/2) * d;
    else kvadrat3 = visina * ((novox / d)/2)* d;
    int kvadrat4 = 0;
    if((((x-1)/d+1) % 2) == (((y-1)/d+1) % 2))kvadrat4 = (x-novox)*(y-novoy);
    return kvadrat1+kvadrat2+kvadrat3+ kvadrat4;
}


signed main()
{
    ios_base::sync_with_stdio(false),cin.tie(0), cout.tie(0);
    int tt=1;
    //cin >> tt;
    while(tt--)
    {

        cin >> n >> k;
        niz.resize(k);
        vector<int> svidelioci;
        svidelioci.pb(1);
        for(int i=0; i<k; i++)cin >> niz[i].x1 >> niz[i].y1 >> niz[i].x2 >> niz[i].y2;
        for(int i=2; i<=sqrt(n); i++)
        {
            if(n%i == 0)
            {
                if(n/i == i)svidelioci.pb(i);
                else
                {
                    svidelioci.pb(i);
                    svidelioci.pb(n/i);
                }
            }
        }
        sort(all(svidelioci));

        for(int x: svidelioci)
        {
            int guess = ((n/x) * (n/x) + 1) / 2 * x * x;
            int guess1 = n*n - guess;
            for(auto y: niz)
            {
                int rez1 = check1(y.x2, y.y2, x);
                int rez2 = check1(y.x2, y.y1-1, x);
                int rez3 = check1(y.x1-1, y.y2, x);
                int rez4 = check1(y.x1-1, y.y1-1, x);
                int brbelih = rez1 + rez4 - rez2 - rez3;
                int brcrnih = (y.x2 - y.x1 + 1) * (y.y2 - y.y1 + 1) - brbelih;
               guess = guess - brbelih + brcrnih;
               guess1 = guess1 + brbelih - brcrnih;

            }
            rez = min({rez, guess, guess1});

        }
        cout << rez << endl;

    }
}

/*
 6 8
 3 3 3 3
 1 2 1 2
 3 4 3 4
 5 5 5 5
 4 3 4 3
 4 4 4 4
 2 1 2 1
 3 6 3 6
*/

/*
4 1
4 1 4 4
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 3676 KB Output is correct
2 Correct 4 ms 1116 KB Output is correct
3 Correct 10 ms 2396 KB Output is correct
4 Correct 11 ms 2540 KB Output is correct
5 Correct 14 ms 3420 KB Output is correct
6 Correct 9 ms 2308 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 9 ms 2192 KB Output is correct
9 Correct 23 ms 5200 KB Output is correct
10 Correct 13 ms 3160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 464 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 464 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 9 ms 1628 KB Output is correct
17 Correct 18 ms 4236 KB Output is correct
18 Correct 34 ms 5108 KB Output is correct
19 Correct 141 ms 4488 KB Output is correct
20 Correct 155 ms 4944 KB Output is correct
21 Correct 19 ms 4188 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 23 ms 2396 KB Output is correct
24 Correct 29 ms 4700 KB Output is correct
25 Correct 7 ms 860 KB Output is correct
26 Correct 19 ms 2904 KB Output is correct
27 Correct 36 ms 3476 KB Output is correct
28 Correct 30 ms 4956 KB Output is correct
29 Correct 8 ms 1884 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 3676 KB Output is correct
2 Correct 4 ms 1116 KB Output is correct
3 Correct 10 ms 2396 KB Output is correct
4 Correct 11 ms 2540 KB Output is correct
5 Correct 14 ms 3420 KB Output is correct
6 Correct 9 ms 2308 KB Output is correct
7 Correct 2 ms 860 KB Output is correct
8 Correct 9 ms 2192 KB Output is correct
9 Correct 23 ms 5200 KB Output is correct
10 Correct 13 ms 3160 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 464 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 9 ms 1628 KB Output is correct
27 Correct 18 ms 4236 KB Output is correct
28 Correct 34 ms 5108 KB Output is correct
29 Correct 141 ms 4488 KB Output is correct
30 Correct 155 ms 4944 KB Output is correct
31 Correct 19 ms 4188 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 23 ms 2396 KB Output is correct
34 Correct 29 ms 4700 KB Output is correct
35 Correct 7 ms 860 KB Output is correct
36 Correct 19 ms 2904 KB Output is correct
37 Correct 36 ms 3476 KB Output is correct
38 Correct 30 ms 4956 KB Output is correct
39 Correct 8 ms 1884 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 112 ms 4964 KB Output is correct
42 Correct 35 ms 5444 KB Output is correct
43 Correct 65 ms 4956 KB Output is correct
44 Correct 33 ms 5464 KB Output is correct
45 Correct 27 ms 5724 KB Output is correct
46 Correct 125 ms 5468 KB Output is correct
47 Correct 22 ms 5052 KB Output is correct
48 Correct 51 ms 5216 KB Output is correct
49 Correct 30 ms 4956 KB Output is correct
50 Correct 582 ms 5212 KB Output is correct
51 Correct 625 ms 5724 KB Output is correct
52 Correct 582 ms 5208 KB Output is correct
53 Correct 621 ms 5716 KB Output is correct
54 Correct 569 ms 5208 KB Output is correct
55 Correct 646 ms 5884 KB Output is correct
56 Correct 557 ms 5212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 460 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 16 ms 3676 KB Output is correct
10 Correct 4 ms 1116 KB Output is correct
11 Correct 10 ms 2396 KB Output is correct
12 Correct 11 ms 2540 KB Output is correct
13 Correct 14 ms 3420 KB Output is correct
14 Correct 9 ms 2308 KB Output is correct
15 Correct 2 ms 860 KB Output is correct
16 Correct 9 ms 2192 KB Output is correct
17 Correct 23 ms 5200 KB Output is correct
18 Correct 13 ms 3160 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 464 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 9 ms 1628 KB Output is correct
35 Correct 18 ms 4236 KB Output is correct
36 Correct 34 ms 5108 KB Output is correct
37 Correct 141 ms 4488 KB Output is correct
38 Correct 155 ms 4944 KB Output is correct
39 Correct 19 ms 4188 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 23 ms 2396 KB Output is correct
42 Correct 29 ms 4700 KB Output is correct
43 Correct 7 ms 860 KB Output is correct
44 Correct 19 ms 2904 KB Output is correct
45 Correct 36 ms 3476 KB Output is correct
46 Correct 30 ms 4956 KB Output is correct
47 Correct 8 ms 1884 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 112 ms 4964 KB Output is correct
50 Correct 35 ms 5444 KB Output is correct
51 Correct 65 ms 4956 KB Output is correct
52 Correct 33 ms 5464 KB Output is correct
53 Correct 27 ms 5724 KB Output is correct
54 Correct 125 ms 5468 KB Output is correct
55 Correct 22 ms 5052 KB Output is correct
56 Correct 51 ms 5216 KB Output is correct
57 Correct 30 ms 4956 KB Output is correct
58 Correct 582 ms 5212 KB Output is correct
59 Correct 625 ms 5724 KB Output is correct
60 Correct 582 ms 5208 KB Output is correct
61 Correct 621 ms 5716 KB Output is correct
62 Correct 569 ms 5208 KB Output is correct
63 Correct 646 ms 5884 KB Output is correct
64 Correct 557 ms 5212 KB Output is correct
65 Correct 0 ms 344 KB Output is correct
66 Correct 0 ms 344 KB Output is correct
67 Correct 618 ms 5428 KB Output is correct
68 Correct 619 ms 5460 KB Output is correct
69 Correct 532 ms 4952 KB Output is correct
70 Correct 581 ms 5208 KB Output is correct
71 Correct 582 ms 5208 KB Output is correct
72 Correct 567 ms 5208 KB Output is correct
73 Correct 563 ms 4956 KB Output is correct
74 Correct 613 ms 5532 KB Output is correct
75 Correct 578 ms 5212 KB Output is correct
76 Correct 617 ms 5468 KB Output is correct
77 Correct 96 ms 5724 KB Output is correct
78 Correct 32 ms 5212 KB Output is correct
79 Correct 65 ms 4956 KB Output is correct
80 Correct 68 ms 5212 KB Output is correct
81 Correct 63 ms 4956 KB Output is correct
82 Correct 52 ms 5468 KB Output is correct
83 Correct 42 ms 5180 KB Output is correct
84 Correct 371 ms 5648 KB Output is correct
85 Correct 653 ms 5740 KB Output is correct
86 Correct 1 ms 344 KB Output is correct
87 Correct 1 ms 348 KB Output is correct
88 Correct 653 ms 5728 KB Output is correct
89 Correct 124 ms 1372 KB Output is correct
90 Correct 0 ms 344 KB Output is correct