답안 #289676

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
289676 2020-09-02T22:33:33 Z luciocf Chessboard (IZhO18_chessboard) C++14
100 / 100
709 ms 4348 KB
#include <bits/stdc++.h>

#define ff first
#define ss second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

const int maxn = 1e5+10;
const ll inf = 1e18+10;

pair<pii, pii> rect[maxn];

ll qtd(int k, int d)
{
	if (k < 0) return 0;
	++k;
	int oldk = k;

	ll ans = (k/(2*d))*d;
	k -= ((k/(2*d))*(2*d));

	return (ans+min(d, k));
}

ll get_menor(int i, int d)
{
	ll linha = qtd(rect[i].ss.ss, d)-qtd(rect[i].ff.ss-1, d);
	ll col = qtd(rect[i].ss.ff, d)-qtd(rect[i].ff.ff-1, d);

	return linha*col;
}

ll get_maior(int i, int d)
{
	ll linha = (rect[i].ss.ss-rect[i].ff.ss+1) - (qtd(rect[i].ss.ss, d)-qtd(rect[i].ff.ss-1, d));
	ll col = (rect[i].ss.ff-rect[i].ff.ff+1) - (qtd(rect[i].ss.ff, d)-qtd(rect[i].ff.ff-1, d));

	return linha*col;
}

int main(void)
{
	int n, k;
	scanf("%d %d", &n, &k);

	for (int i = 1; i <= k; i++)
	{
		scanf("%d %d", &rect[i].ff.ff, &rect[i].ff.ss);
		scanf("%d %d", &rect[i].ss.ff, &rect[i].ss.ss);

		rect[i].ff.ff--, rect[i].ff.ss--;
		rect[i].ss.ff--, rect[i].ss.ss--;
	}

	vector<int> D;

	for (int d = 1; d*d <= n; d++)
	{
		if (n%d) continue;

		D.push_back(d);
		if (n/d != d) D.push_back(n/d);
	}

	ll ans = inf;

	for (auto d: D)
	{
		if (d == n) continue;

		ll p = 0, b = 0;

		for (int i = 1; i <= k; i++)
		{
			ll x = get_menor(i, d) + get_maior(i, d);

			p += x;

			b += (1ll*(rect[i].ss.ff-rect[i].ff.ff+1)*(rect[i].ss.ss-rect[i].ff.ss+1) - x);
		}

		ll x = ((n+2*d-1)/(2*d));
		ll y = n/(2*d);

		ll tot_p = 1ll*d*d*(x*x+y*y);

		ans = min(ans, (tot_p-p)+b);

		swap(p, b);
		tot_p = 1ll*n*n-tot_p;

		ans = min(ans, (tot_p-p)+b);
	}

	printf("%lld\n", ans);
}

Compilation message

chessboard.cpp: In function 'll qtd(int, int)':
chessboard.cpp:20:6: warning: unused variable 'oldk' [-Wunused-variable]
   20 |  int oldk = k;
      |      ^~~~
chessboard.cpp: In function 'int main()':
chessboard.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |  scanf("%d %d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~
chessboard.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |   scanf("%d %d", &rect[i].ff.ff, &rect[i].ff.ss);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chessboard.cpp:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   52 |   scanf("%d %d", &rect[i].ss.ff, &rect[i].ss.ss);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 1272 KB Output is correct
2 Correct 10 ms 512 KB Output is correct
3 Correct 24 ms 976 KB Output is correct
4 Correct 24 ms 1016 KB Output is correct
5 Correct 31 ms 1152 KB Output is correct
6 Correct 20 ms 896 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 21 ms 896 KB Output is correct
9 Correct 53 ms 1660 KB Output is correct
10 Correct 29 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 16 ms 768 KB Output is correct
17 Correct 41 ms 1656 KB Output is correct
18 Correct 57 ms 1912 KB Output is correct
19 Correct 152 ms 1784 KB Output is correct
20 Correct 171 ms 1784 KB Output is correct
21 Correct 39 ms 1528 KB Output is correct
22 Correct 1 ms 256 KB Output is correct
23 Correct 33 ms 1024 KB Output is correct
24 Correct 52 ms 1792 KB Output is correct
25 Correct 7 ms 512 KB Output is correct
26 Correct 33 ms 1152 KB Output is correct
27 Correct 57 ms 1400 KB Output is correct
28 Correct 60 ms 1792 KB Output is correct
29 Correct 16 ms 768 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 1272 KB Output is correct
2 Correct 10 ms 512 KB Output is correct
3 Correct 24 ms 976 KB Output is correct
4 Correct 24 ms 1016 KB Output is correct
5 Correct 31 ms 1152 KB Output is correct
6 Correct 20 ms 896 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 21 ms 896 KB Output is correct
9 Correct 53 ms 1660 KB Output is correct
10 Correct 29 ms 1144 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 16 ms 768 KB Output is correct
27 Correct 41 ms 1656 KB Output is correct
28 Correct 57 ms 1912 KB Output is correct
29 Correct 152 ms 1784 KB Output is correct
30 Correct 171 ms 1784 KB Output is correct
31 Correct 39 ms 1528 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 33 ms 1024 KB Output is correct
34 Correct 52 ms 1792 KB Output is correct
35 Correct 7 ms 512 KB Output is correct
36 Correct 33 ms 1152 KB Output is correct
37 Correct 57 ms 1400 KB Output is correct
38 Correct 60 ms 1792 KB Output is correct
39 Correct 16 ms 768 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 145 ms 1656 KB Output is correct
42 Correct 64 ms 1784 KB Output is correct
43 Correct 92 ms 1656 KB Output is correct
44 Correct 65 ms 1784 KB Output is correct
45 Correct 57 ms 1784 KB Output is correct
46 Correct 166 ms 1784 KB Output is correct
47 Correct 51 ms 1616 KB Output is correct
48 Correct 79 ms 1656 KB Output is correct
49 Correct 59 ms 1656 KB Output is correct
50 Correct 655 ms 1788 KB Output is correct
51 Correct 683 ms 1912 KB Output is correct
52 Correct 645 ms 1776 KB Output is correct
53 Correct 688 ms 1864 KB Output is correct
54 Correct 629 ms 1784 KB Output is correct
55 Correct 700 ms 2040 KB Output is correct
56 Correct 611 ms 1784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 36 ms 1272 KB Output is correct
10 Correct 10 ms 512 KB Output is correct
11 Correct 24 ms 976 KB Output is correct
12 Correct 24 ms 1016 KB Output is correct
13 Correct 31 ms 1152 KB Output is correct
14 Correct 20 ms 896 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 21 ms 896 KB Output is correct
17 Correct 53 ms 1660 KB Output is correct
18 Correct 29 ms 1144 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 256 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 16 ms 768 KB Output is correct
35 Correct 41 ms 1656 KB Output is correct
36 Correct 57 ms 1912 KB Output is correct
37 Correct 152 ms 1784 KB Output is correct
38 Correct 171 ms 1784 KB Output is correct
39 Correct 39 ms 1528 KB Output is correct
40 Correct 1 ms 256 KB Output is correct
41 Correct 33 ms 1024 KB Output is correct
42 Correct 52 ms 1792 KB Output is correct
43 Correct 7 ms 512 KB Output is correct
44 Correct 33 ms 1152 KB Output is correct
45 Correct 57 ms 1400 KB Output is correct
46 Correct 60 ms 1792 KB Output is correct
47 Correct 16 ms 768 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 145 ms 1656 KB Output is correct
50 Correct 64 ms 1784 KB Output is correct
51 Correct 92 ms 1656 KB Output is correct
52 Correct 65 ms 1784 KB Output is correct
53 Correct 57 ms 1784 KB Output is correct
54 Correct 166 ms 1784 KB Output is correct
55 Correct 51 ms 1616 KB Output is correct
56 Correct 79 ms 1656 KB Output is correct
57 Correct 59 ms 1656 KB Output is correct
58 Correct 655 ms 1788 KB Output is correct
59 Correct 683 ms 1912 KB Output is correct
60 Correct 645 ms 1776 KB Output is correct
61 Correct 688 ms 1864 KB Output is correct
62 Correct 629 ms 1784 KB Output is correct
63 Correct 700 ms 2040 KB Output is correct
64 Correct 611 ms 1784 KB Output is correct
65 Correct 0 ms 256 KB Output is correct
66 Correct 0 ms 256 KB Output is correct
67 Correct 658 ms 4056 KB Output is correct
68 Correct 663 ms 3960 KB Output is correct
69 Correct 597 ms 3576 KB Output is correct
70 Correct 647 ms 3832 KB Output is correct
71 Correct 631 ms 3880 KB Output is correct
72 Correct 625 ms 3832 KB Output is correct
73 Correct 605 ms 3728 KB Output is correct
74 Correct 652 ms 3960 KB Output is correct
75 Correct 640 ms 3832 KB Output is correct
76 Correct 671 ms 4088 KB Output is correct
77 Correct 130 ms 4216 KB Output is correct
78 Correct 63 ms 3960 KB Output is correct
79 Correct 93 ms 3704 KB Output is correct
80 Correct 99 ms 3832 KB Output is correct
81 Correct 96 ms 3704 KB Output is correct
82 Correct 86 ms 3960 KB Output is correct
83 Correct 73 ms 3708 KB Output is correct
84 Correct 410 ms 4180 KB Output is correct
85 Correct 700 ms 4216 KB Output is correct
86 Correct 1 ms 256 KB Output is correct
87 Correct 1 ms 256 KB Output is correct
88 Correct 709 ms 4348 KB Output is correct
89 Correct 133 ms 1024 KB Output is correct
90 Correct 1 ms 256 KB Output is correct