답안 #896260

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
896260 2024-01-01T06:20:40 Z CyberCow Chessboard (IZhO18_chessboard) C++17
100 / 100
336 ms 2864 KB
#include <random>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#define fr first
#define sc second
#define ad push_back
using namespace std;
using ll = long long;
mt19937 rnd(348502);

const int N = 100005;

pair<ll, ll> ans[N];

void solve()
{
    ll n, i, j, x, y, x1, y1, k;
    cin >> n >> k;
    vector<ll> baj;
    baj.push_back(1);
    for (i = 2; i * i < n; i++)
    {
        if (n % i == 0)
        {
            baj.push_back(i);
            baj.push_back(n / i);
        }
    }
    if (i * i == n)
        baj.push_back(i);
    for (i = 0; i < baj.size(); i++)
    {
        if ((n / baj[i]) % 2 == 1)
        {
            ans[i] = { (n / baj[i]) * (n / baj[i]) / 2 * baj[i] * baj[i], ((n / baj[i]) * (n / baj[i]) / 2 + 1) * baj[i] * baj[i] };
        }
        else
        {
            ans[i] = { n * n / 2, n * n / 2 };
        }
    }
    for (i = 0; i < k; i++)
    {
        cin >> x >> y >> x1 >> y1;
        for (j = 0; j < baj.size(); j++)
        {
            ll sev, sptiak;
            sev = min((x - 1) / baj[j] * baj[j] + baj[j] + 1, x1 + 1) - x;
            sev += max((x1 / baj[j] * baj[j]) - ((x - 1) / baj[j] * baj[j] + baj[j]), 0LL) / baj[j] / 2 * baj[j];
            if ((max((x1 / baj[j] * baj[j]) - ((x - 1) / baj[j] * baj[j] + baj[j]), 0LL) / baj[j]) % 2 == 1)
            {
                sev += x1 - x1 / baj[j] * baj[j];
            }
            sptiak = x1 - x + 1 - sev;
            ll sevy, sptiaky;
            sevy = min((y - 1) / baj[j] * baj[j] + baj[j] + 1, y1 + 1) - y;
            sevy += max((y1 / baj[j] * baj[j]) - ((y - 1) / baj[j] * baj[j] + baj[j]), 0LL) / baj[j] / 2 * baj[j];
            if ((max((y1 / baj[j] * baj[j]) - ((y - 1) / baj[j] * baj[j] + baj[j]), 0LL) / baj[j]) % 2 == 1)
            {
                sevy += y1 - y1 / baj[j] * baj[j];
            }
            sptiaky = y1 - y + 1 - sevy;
            ll obshisev = sev * sevy + sptiaky * sptiak;
            ll obshisptiak = sevy * sptiak + sptiaky * sev;
            if (((x - 1) / baj[j] + (y - 1) / baj[j]) % 2 == 1)
            {
                ans[j].first -= obshisev - obshisptiak;
                ans[j].second -= obshisptiak - obshisev;
            }
            else
            {
                ans[j].first -= obshisptiak - obshisev;
                ans[j].second -= obshisev - obshisptiak;
            }
        }
    }
    ll anss = 1e18;
    for (i = 0; i < baj.size(); i++)
    {
        anss = min(anss, min(ans[i].first, ans[i].second));
    }
    cout << anss;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

Compilation message

chessboard.cpp: In function 'void solve()':
chessboard.cpp:48:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (i = 0; i < baj.size(); i++)
      |                 ~~^~~~~~~~~~~~
chessboard.cpp:62:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for (j = 0; j < baj.size(); j++)
      |                     ~~^~~~~~~~~~~~
chessboard.cpp:95:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |     for (i = 0; i < baj.size(); i++)
      |                 ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 17 ms 468 KB Output is correct
2 Correct 5 ms 604 KB Output is correct
3 Correct 12 ms 1220 KB Output is correct
4 Correct 11 ms 1116 KB Output is correct
5 Correct 15 ms 1628 KB Output is correct
6 Correct 10 ms 1368 KB Output is correct
7 Correct 3 ms 480 KB Output is correct
8 Correct 11 ms 1368 KB Output is correct
9 Correct 23 ms 2396 KB Output is correct
10 Correct 14 ms 1624 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 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 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 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 372 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 0 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 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 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 372 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 10 ms 856 KB Output is correct
17 Correct 18 ms 1620 KB Output is correct
18 Correct 29 ms 1852 KB Output is correct
19 Correct 72 ms 1836 KB Output is correct
20 Correct 80 ms 1984 KB Output is correct
21 Correct 18 ms 1628 KB Output is correct
22 Correct 1 ms 360 KB Output is correct
23 Correct 16 ms 1168 KB Output is correct
24 Correct 24 ms 1748 KB Output is correct
25 Correct 4 ms 616 KB Output is correct
26 Correct 16 ms 1380 KB Output is correct
27 Correct 22 ms 1352 KB Output is correct
28 Correct 26 ms 1992 KB Output is correct
29 Correct 8 ms 1000 KB Output is correct
30 Correct 1 ms 356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 468 KB Output is correct
2 Correct 5 ms 604 KB Output is correct
3 Correct 12 ms 1220 KB Output is correct
4 Correct 11 ms 1116 KB Output is correct
5 Correct 15 ms 1628 KB Output is correct
6 Correct 10 ms 1368 KB Output is correct
7 Correct 3 ms 480 KB Output is correct
8 Correct 11 ms 1368 KB Output is correct
9 Correct 23 ms 2396 KB Output is correct
10 Correct 14 ms 1624 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 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 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 372 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 10 ms 856 KB Output is correct
27 Correct 18 ms 1620 KB Output is correct
28 Correct 29 ms 1852 KB Output is correct
29 Correct 72 ms 1836 KB Output is correct
30 Correct 80 ms 1984 KB Output is correct
31 Correct 18 ms 1628 KB Output is correct
32 Correct 1 ms 360 KB Output is correct
33 Correct 16 ms 1168 KB Output is correct
34 Correct 24 ms 1748 KB Output is correct
35 Correct 4 ms 616 KB Output is correct
36 Correct 16 ms 1380 KB Output is correct
37 Correct 22 ms 1352 KB Output is correct
38 Correct 26 ms 1992 KB Output is correct
39 Correct 8 ms 1000 KB Output is correct
40 Correct 1 ms 356 KB Output is correct
41 Correct 65 ms 2400 KB Output is correct
42 Correct 29 ms 2652 KB Output is correct
43 Correct 42 ms 2452 KB Output is correct
44 Correct 34 ms 2396 KB Output is correct
45 Correct 25 ms 2652 KB Output is correct
46 Correct 72 ms 2628 KB Output is correct
47 Correct 23 ms 2396 KB Output is correct
48 Correct 35 ms 2368 KB Output is correct
49 Correct 26 ms 2392 KB Output is correct
50 Correct 287 ms 2624 KB Output is correct
51 Correct 305 ms 2608 KB Output is correct
52 Correct 288 ms 2384 KB Output is correct
53 Correct 303 ms 2500 KB Output is correct
54 Correct 286 ms 2388 KB Output is correct
55 Correct 315 ms 2732 KB Output is correct
56 Correct 275 ms 2488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 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 17 ms 468 KB Output is correct
10 Correct 5 ms 604 KB Output is correct
11 Correct 12 ms 1220 KB Output is correct
12 Correct 11 ms 1116 KB Output is correct
13 Correct 15 ms 1628 KB Output is correct
14 Correct 10 ms 1368 KB Output is correct
15 Correct 3 ms 480 KB Output is correct
16 Correct 11 ms 1368 KB Output is correct
17 Correct 23 ms 2396 KB Output is correct
18 Correct 14 ms 1624 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 1 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 1 ms 344 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 372 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 10 ms 856 KB Output is correct
35 Correct 18 ms 1620 KB Output is correct
36 Correct 29 ms 1852 KB Output is correct
37 Correct 72 ms 1836 KB Output is correct
38 Correct 80 ms 1984 KB Output is correct
39 Correct 18 ms 1628 KB Output is correct
40 Correct 1 ms 360 KB Output is correct
41 Correct 16 ms 1168 KB Output is correct
42 Correct 24 ms 1748 KB Output is correct
43 Correct 4 ms 616 KB Output is correct
44 Correct 16 ms 1380 KB Output is correct
45 Correct 22 ms 1352 KB Output is correct
46 Correct 26 ms 1992 KB Output is correct
47 Correct 8 ms 1000 KB Output is correct
48 Correct 1 ms 356 KB Output is correct
49 Correct 65 ms 2400 KB Output is correct
50 Correct 29 ms 2652 KB Output is correct
51 Correct 42 ms 2452 KB Output is correct
52 Correct 34 ms 2396 KB Output is correct
53 Correct 25 ms 2652 KB Output is correct
54 Correct 72 ms 2628 KB Output is correct
55 Correct 23 ms 2396 KB Output is correct
56 Correct 35 ms 2368 KB Output is correct
57 Correct 26 ms 2392 KB Output is correct
58 Correct 287 ms 2624 KB Output is correct
59 Correct 305 ms 2608 KB Output is correct
60 Correct 288 ms 2384 KB Output is correct
61 Correct 303 ms 2500 KB Output is correct
62 Correct 286 ms 2388 KB Output is correct
63 Correct 315 ms 2732 KB Output is correct
64 Correct 275 ms 2488 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 348 KB Output is correct
67 Correct 314 ms 2484 KB Output is correct
68 Correct 314 ms 2864 KB Output is correct
69 Correct 272 ms 2384 KB Output is correct
70 Correct 312 ms 2384 KB Output is correct
71 Correct 301 ms 2588 KB Output is correct
72 Correct 293 ms 2484 KB Output is correct
73 Correct 289 ms 2644 KB Output is correct
74 Correct 310 ms 2640 KB Output is correct
75 Correct 305 ms 2356 KB Output is correct
76 Correct 324 ms 2720 KB Output is correct
77 Correct 62 ms 2644 KB Output is correct
78 Correct 28 ms 2744 KB Output is correct
79 Correct 44 ms 2364 KB Output is correct
80 Correct 46 ms 2360 KB Output is correct
81 Correct 43 ms 2384 KB Output is correct
82 Correct 40 ms 2492 KB Output is correct
83 Correct 32 ms 2488 KB Output is correct
84 Correct 195 ms 2736 KB Output is correct
85 Correct 332 ms 2640 KB Output is correct
86 Correct 1 ms 348 KB Output is correct
87 Correct 0 ms 348 KB Output is correct
88 Correct 336 ms 2640 KB Output is correct
89 Correct 64 ms 908 KB Output is correct
90 Correct 1 ms 344 KB Output is correct