Submission #68106

# Submission time Handle Problem Language Result Execution time Memory
68106 2018-08-15T23:32:20 Z MatheusLealV Chessboard (IZhO18_chessboard) C++17
100 / 100
1182 ms 3836 KB
#include <bits/stdc++.h>
#define N 100050
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

ll n, k, x[N], y[N], xf[N], yf[N];

ll ans = (2000000000000000000ll);

vector<ll> d;

inline ll conta(ll x, ll y, ll r)
{
	x ++, y ++;

	ll tx = (x/r), ty = (y/r);

	int rx = (tx % 2 == 0 ? 1 : 0), ry = (ty % 2 == 0 ? 1 : 0);

	ll xo = ((tx + 1)/2)*r + (rx ? x % r : 0);

	ll xi = (x - xo);

	ll yo = ((ty + 1)/2)*r + (ry ? y % r : 0);

	ll yi = (y - yo);

	return xo*yo + xi*yi;
}

inline ll custo(ll xi, ll yi, ll xii, ll yii, ll r)
{
	ll C = conta(xii, yii, r) - conta(xi - 1, yii, r) - conta(xii, yi - 1, r) + conta(xi - 1, yi - 1, r);

	return C;
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);

	cin>>n>>k;

	for(int i = 1; i <= k; i++) cin>>x[i]>>y[i]>>xf[i]>>yf[i];

	for(int i = 1; i <= k; i++) 
	{
		x[i] --, y[i] --, xf[i] --, yf[i] --;

		if(x[i] > xf[i]) swap(x[i], xf[i]);

		if(y[i] > yf[i]) swap(y[i], yf[i]);
	}

	for(int i = 1; i <= sqrt(n); i++)
	{
		if((n % i) != 0) continue;

		d.push_back(i);

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

	for(auto r: d)
	{	
		ll pretocerto = 0, pretoerrado = 0, tot;

		if(r == n) continue;

		tot = ( ((n/r) * (n/r)) + 1LL)/2LL;

		tot = (tot * r * r); 

		for(int i = 1; i <= k; i++)
		{
			ll S = custo(x[i], y[i], xf[i], yf[i], r);

			pretocerto += S;

			pretoerrado += (xf[i] - x[i] + 1) * (yf[i] - y[i] + 1) - S;
		}

		ans = min(ans, tot - pretocerto + pretoerrado);

		tot = ( ((n/r) * (n/r)))/2LL;

		tot = (tot * r * r); 

		ans = min(ans, tot + pretocerto - pretoerrado);

	}

	cout<<ans<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 520 KB Output is correct
4 Correct 2 ms 520 KB Output is correct
5 Correct 2 ms 520 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 3 ms 636 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 2480 KB Output is correct
2 Correct 10 ms 2480 KB Output is correct
3 Correct 23 ms 2480 KB Output is correct
4 Correct 27 ms 2480 KB Output is correct
5 Correct 31 ms 2480 KB Output is correct
6 Correct 21 ms 2480 KB Output is correct
7 Correct 6 ms 2480 KB Output is correct
8 Correct 22 ms 2480 KB Output is correct
9 Correct 52 ms 3428 KB Output is correct
10 Correct 30 ms 3428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3428 KB Output is correct
2 Correct 2 ms 3428 KB Output is correct
3 Correct 3 ms 3428 KB Output is correct
4 Correct 3 ms 3428 KB Output is correct
5 Correct 3 ms 3428 KB Output is correct
6 Correct 4 ms 3428 KB Output is correct
7 Correct 4 ms 3428 KB Output is correct
8 Correct 2 ms 3428 KB Output is correct
9 Correct 2 ms 3428 KB Output is correct
10 Correct 2 ms 3428 KB Output is correct
11 Correct 2 ms 3428 KB Output is correct
12 Correct 2 ms 3428 KB Output is correct
13 Correct 3 ms 3428 KB Output is correct
14 Correct 3 ms 3428 KB Output is correct
15 Correct 4 ms 3428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3428 KB Output is correct
2 Correct 2 ms 3428 KB Output is correct
3 Correct 3 ms 3428 KB Output is correct
4 Correct 3 ms 3428 KB Output is correct
5 Correct 3 ms 3428 KB Output is correct
6 Correct 4 ms 3428 KB Output is correct
7 Correct 4 ms 3428 KB Output is correct
8 Correct 2 ms 3428 KB Output is correct
9 Correct 2 ms 3428 KB Output is correct
10 Correct 2 ms 3428 KB Output is correct
11 Correct 2 ms 3428 KB Output is correct
12 Correct 2 ms 3428 KB Output is correct
13 Correct 3 ms 3428 KB Output is correct
14 Correct 3 ms 3428 KB Output is correct
15 Correct 4 ms 3428 KB Output is correct
16 Correct 22 ms 3428 KB Output is correct
17 Correct 48 ms 3428 KB Output is correct
18 Correct 72 ms 3696 KB Output is correct
19 Correct 250 ms 3696 KB Output is correct
20 Correct 265 ms 3696 KB Output is correct
21 Correct 46 ms 3696 KB Output is correct
22 Correct 3 ms 3696 KB Output is correct
23 Correct 43 ms 3696 KB Output is correct
24 Correct 54 ms 3696 KB Output is correct
25 Correct 11 ms 3696 KB Output is correct
26 Correct 44 ms 3696 KB Output is correct
27 Correct 54 ms 3696 KB Output is correct
28 Correct 68 ms 3696 KB Output is correct
29 Correct 18 ms 3696 KB Output is correct
30 Correct 4 ms 3696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 2480 KB Output is correct
2 Correct 10 ms 2480 KB Output is correct
3 Correct 23 ms 2480 KB Output is correct
4 Correct 27 ms 2480 KB Output is correct
5 Correct 31 ms 2480 KB Output is correct
6 Correct 21 ms 2480 KB Output is correct
7 Correct 6 ms 2480 KB Output is correct
8 Correct 22 ms 2480 KB Output is correct
9 Correct 52 ms 3428 KB Output is correct
10 Correct 30 ms 3428 KB Output is correct
11 Correct 3 ms 3428 KB Output is correct
12 Correct 2 ms 3428 KB Output is correct
13 Correct 3 ms 3428 KB Output is correct
14 Correct 3 ms 3428 KB Output is correct
15 Correct 3 ms 3428 KB Output is correct
16 Correct 4 ms 3428 KB Output is correct
17 Correct 4 ms 3428 KB Output is correct
18 Correct 2 ms 3428 KB Output is correct
19 Correct 2 ms 3428 KB Output is correct
20 Correct 2 ms 3428 KB Output is correct
21 Correct 2 ms 3428 KB Output is correct
22 Correct 2 ms 3428 KB Output is correct
23 Correct 3 ms 3428 KB Output is correct
24 Correct 3 ms 3428 KB Output is correct
25 Correct 4 ms 3428 KB Output is correct
26 Correct 22 ms 3428 KB Output is correct
27 Correct 48 ms 3428 KB Output is correct
28 Correct 72 ms 3696 KB Output is correct
29 Correct 250 ms 3696 KB Output is correct
30 Correct 265 ms 3696 KB Output is correct
31 Correct 46 ms 3696 KB Output is correct
32 Correct 3 ms 3696 KB Output is correct
33 Correct 43 ms 3696 KB Output is correct
34 Correct 54 ms 3696 KB Output is correct
35 Correct 11 ms 3696 KB Output is correct
36 Correct 44 ms 3696 KB Output is correct
37 Correct 54 ms 3696 KB Output is correct
38 Correct 68 ms 3696 KB Output is correct
39 Correct 18 ms 3696 KB Output is correct
40 Correct 4 ms 3696 KB Output is correct
41 Correct 291 ms 3696 KB Output is correct
42 Correct 70 ms 3696 KB Output is correct
43 Correct 115 ms 3696 KB Output is correct
44 Correct 62 ms 3696 KB Output is correct
45 Correct 60 ms 3696 KB Output is correct
46 Correct 221 ms 3696 KB Output is correct
47 Correct 52 ms 3696 KB Output is correct
48 Correct 102 ms 3696 KB Output is correct
49 Correct 67 ms 3696 KB Output is correct
50 Correct 1022 ms 3696 KB Output is correct
51 Correct 1116 ms 3708 KB Output is correct
52 Correct 1022 ms 3708 KB Output is correct
53 Correct 1118 ms 3708 KB Output is correct
54 Correct 966 ms 3708 KB Output is correct
55 Correct 1096 ms 3836 KB Output is correct
56 Correct 1008 ms 3836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 520 KB Output is correct
4 Correct 2 ms 520 KB Output is correct
5 Correct 2 ms 520 KB Output is correct
6 Correct 2 ms 636 KB Output is correct
7 Correct 3 ms 636 KB Output is correct
8 Correct 2 ms 636 KB Output is correct
9 Correct 37 ms 2480 KB Output is correct
10 Correct 10 ms 2480 KB Output is correct
11 Correct 23 ms 2480 KB Output is correct
12 Correct 27 ms 2480 KB Output is correct
13 Correct 31 ms 2480 KB Output is correct
14 Correct 21 ms 2480 KB Output is correct
15 Correct 6 ms 2480 KB Output is correct
16 Correct 22 ms 2480 KB Output is correct
17 Correct 52 ms 3428 KB Output is correct
18 Correct 30 ms 3428 KB Output is correct
19 Correct 3 ms 3428 KB Output is correct
20 Correct 2 ms 3428 KB Output is correct
21 Correct 3 ms 3428 KB Output is correct
22 Correct 3 ms 3428 KB Output is correct
23 Correct 3 ms 3428 KB Output is correct
24 Correct 4 ms 3428 KB Output is correct
25 Correct 4 ms 3428 KB Output is correct
26 Correct 2 ms 3428 KB Output is correct
27 Correct 2 ms 3428 KB Output is correct
28 Correct 2 ms 3428 KB Output is correct
29 Correct 2 ms 3428 KB Output is correct
30 Correct 2 ms 3428 KB Output is correct
31 Correct 3 ms 3428 KB Output is correct
32 Correct 3 ms 3428 KB Output is correct
33 Correct 4 ms 3428 KB Output is correct
34 Correct 22 ms 3428 KB Output is correct
35 Correct 48 ms 3428 KB Output is correct
36 Correct 72 ms 3696 KB Output is correct
37 Correct 250 ms 3696 KB Output is correct
38 Correct 265 ms 3696 KB Output is correct
39 Correct 46 ms 3696 KB Output is correct
40 Correct 3 ms 3696 KB Output is correct
41 Correct 43 ms 3696 KB Output is correct
42 Correct 54 ms 3696 KB Output is correct
43 Correct 11 ms 3696 KB Output is correct
44 Correct 44 ms 3696 KB Output is correct
45 Correct 54 ms 3696 KB Output is correct
46 Correct 68 ms 3696 KB Output is correct
47 Correct 18 ms 3696 KB Output is correct
48 Correct 4 ms 3696 KB Output is correct
49 Correct 291 ms 3696 KB Output is correct
50 Correct 70 ms 3696 KB Output is correct
51 Correct 115 ms 3696 KB Output is correct
52 Correct 62 ms 3696 KB Output is correct
53 Correct 60 ms 3696 KB Output is correct
54 Correct 221 ms 3696 KB Output is correct
55 Correct 52 ms 3696 KB Output is correct
56 Correct 102 ms 3696 KB Output is correct
57 Correct 67 ms 3696 KB Output is correct
58 Correct 1022 ms 3696 KB Output is correct
59 Correct 1116 ms 3708 KB Output is correct
60 Correct 1022 ms 3708 KB Output is correct
61 Correct 1118 ms 3708 KB Output is correct
62 Correct 966 ms 3708 KB Output is correct
63 Correct 1096 ms 3836 KB Output is correct
64 Correct 1008 ms 3836 KB Output is correct
65 Correct 3 ms 3836 KB Output is correct
66 Correct 4 ms 3836 KB Output is correct
67 Correct 1127 ms 3836 KB Output is correct
68 Correct 1077 ms 3836 KB Output is correct
69 Correct 926 ms 3836 KB Output is correct
70 Correct 998 ms 3836 KB Output is correct
71 Correct 926 ms 3836 KB Output is correct
72 Correct 906 ms 3836 KB Output is correct
73 Correct 914 ms 3836 KB Output is correct
74 Correct 1000 ms 3836 KB Output is correct
75 Correct 939 ms 3836 KB Output is correct
76 Correct 1042 ms 3836 KB Output is correct
77 Correct 163 ms 3836 KB Output is correct
78 Correct 70 ms 3836 KB Output is correct
79 Correct 119 ms 3836 KB Output is correct
80 Correct 113 ms 3836 KB Output is correct
81 Correct 129 ms 3836 KB Output is correct
82 Correct 92 ms 3836 KB Output is correct
83 Correct 75 ms 3836 KB Output is correct
84 Correct 598 ms 3836 KB Output is correct
85 Correct 1182 ms 3836 KB Output is correct
86 Correct 3 ms 3836 KB Output is correct
87 Correct 2 ms 3836 KB Output is correct
88 Correct 1117 ms 3836 KB Output is correct
89 Correct 209 ms 3836 KB Output is correct
90 Correct 2 ms 3836 KB Output is correct