답안 #68105

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68105 2018-08-15T23:31:25 Z MatheusLealV Chessboard (IZhO18_chessboard) C++17
100 / 100
1169 ms 47424 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];

long long 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);

			//cout<<"CUSTO "<<x[i]<<" "<<y[i]<<" "<<xf[i]<<" "<<yf[i]<<" = "<<S<<"\n";

			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";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 3 ms 656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 2480 KB Output is correct
2 Correct 13 ms 2480 KB Output is correct
3 Correct 23 ms 2480 KB Output is correct
4 Correct 38 ms 2480 KB Output is correct
5 Correct 44 ms 2480 KB Output is correct
6 Correct 32 ms 2480 KB Output is correct
7 Correct 8 ms 2480 KB Output is correct
8 Correct 21 ms 2480 KB Output is correct
9 Correct 56 ms 3436 KB Output is correct
10 Correct 31 ms 3436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3436 KB Output is correct
2 Correct 2 ms 3436 KB Output is correct
3 Correct 2 ms 3436 KB Output is correct
4 Correct 4 ms 3436 KB Output is correct
5 Correct 3 ms 3436 KB Output is correct
6 Correct 3 ms 3436 KB Output is correct
7 Correct 2 ms 3436 KB Output is correct
8 Correct 3 ms 3436 KB Output is correct
9 Correct 3 ms 3436 KB Output is correct
10 Correct 2 ms 3436 KB Output is correct
11 Correct 3 ms 3436 KB Output is correct
12 Correct 2 ms 3436 KB Output is correct
13 Correct 3 ms 3436 KB Output is correct
14 Correct 4 ms 3436 KB Output is correct
15 Correct 4 ms 3436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3436 KB Output is correct
2 Correct 2 ms 3436 KB Output is correct
3 Correct 2 ms 3436 KB Output is correct
4 Correct 4 ms 3436 KB Output is correct
5 Correct 3 ms 3436 KB Output is correct
6 Correct 3 ms 3436 KB Output is correct
7 Correct 2 ms 3436 KB Output is correct
8 Correct 3 ms 3436 KB Output is correct
9 Correct 3 ms 3436 KB Output is correct
10 Correct 2 ms 3436 KB Output is correct
11 Correct 3 ms 3436 KB Output is correct
12 Correct 2 ms 3436 KB Output is correct
13 Correct 3 ms 3436 KB Output is correct
14 Correct 4 ms 3436 KB Output is correct
15 Correct 4 ms 3436 KB Output is correct
16 Correct 23 ms 3436 KB Output is correct
17 Correct 48 ms 3436 KB Output is correct
18 Correct 61 ms 3708 KB Output is correct
19 Correct 249 ms 3708 KB Output is correct
20 Correct 285 ms 3836 KB Output is correct
21 Correct 36 ms 3836 KB Output is correct
22 Correct 3 ms 3836 KB Output is correct
23 Correct 43 ms 3836 KB Output is correct
24 Correct 57 ms 3836 KB Output is correct
25 Correct 11 ms 3836 KB Output is correct
26 Correct 56 ms 3836 KB Output is correct
27 Correct 84 ms 3836 KB Output is correct
28 Correct 58 ms 3836 KB Output is correct
29 Correct 27 ms 3836 KB Output is correct
30 Correct 4 ms 3836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 2480 KB Output is correct
2 Correct 13 ms 2480 KB Output is correct
3 Correct 23 ms 2480 KB Output is correct
4 Correct 38 ms 2480 KB Output is correct
5 Correct 44 ms 2480 KB Output is correct
6 Correct 32 ms 2480 KB Output is correct
7 Correct 8 ms 2480 KB Output is correct
8 Correct 21 ms 2480 KB Output is correct
9 Correct 56 ms 3436 KB Output is correct
10 Correct 31 ms 3436 KB Output is correct
11 Correct 3 ms 3436 KB Output is correct
12 Correct 2 ms 3436 KB Output is correct
13 Correct 2 ms 3436 KB Output is correct
14 Correct 4 ms 3436 KB Output is correct
15 Correct 3 ms 3436 KB Output is correct
16 Correct 3 ms 3436 KB Output is correct
17 Correct 2 ms 3436 KB Output is correct
18 Correct 3 ms 3436 KB Output is correct
19 Correct 3 ms 3436 KB Output is correct
20 Correct 2 ms 3436 KB Output is correct
21 Correct 3 ms 3436 KB Output is correct
22 Correct 2 ms 3436 KB Output is correct
23 Correct 3 ms 3436 KB Output is correct
24 Correct 4 ms 3436 KB Output is correct
25 Correct 4 ms 3436 KB Output is correct
26 Correct 23 ms 3436 KB Output is correct
27 Correct 48 ms 3436 KB Output is correct
28 Correct 61 ms 3708 KB Output is correct
29 Correct 249 ms 3708 KB Output is correct
30 Correct 285 ms 3836 KB Output is correct
31 Correct 36 ms 3836 KB Output is correct
32 Correct 3 ms 3836 KB Output is correct
33 Correct 43 ms 3836 KB Output is correct
34 Correct 57 ms 3836 KB Output is correct
35 Correct 11 ms 3836 KB Output is correct
36 Correct 56 ms 3836 KB Output is correct
37 Correct 84 ms 3836 KB Output is correct
38 Correct 58 ms 3836 KB Output is correct
39 Correct 27 ms 3836 KB Output is correct
40 Correct 4 ms 3836 KB Output is correct
41 Correct 217 ms 3836 KB Output is correct
42 Correct 73 ms 3836 KB Output is correct
43 Correct 110 ms 3836 KB Output is correct
44 Correct 99 ms 3836 KB Output is correct
45 Correct 60 ms 3836 KB Output is correct
46 Correct 271 ms 3836 KB Output is correct
47 Correct 48 ms 3836 KB Output is correct
48 Correct 96 ms 3836 KB Output is correct
49 Correct 60 ms 3836 KB Output is correct
50 Correct 1042 ms 3836 KB Output is correct
51 Correct 1028 ms 3836 KB Output is correct
52 Correct 1002 ms 3836 KB Output is correct
53 Correct 1169 ms 3836 KB Output is correct
54 Correct 1051 ms 3836 KB Output is correct
55 Correct 1151 ms 3836 KB Output is correct
56 Correct 1053 ms 3836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 3 ms 656 KB Output is correct
9 Correct 35 ms 2480 KB Output is correct
10 Correct 13 ms 2480 KB Output is correct
11 Correct 23 ms 2480 KB Output is correct
12 Correct 38 ms 2480 KB Output is correct
13 Correct 44 ms 2480 KB Output is correct
14 Correct 32 ms 2480 KB Output is correct
15 Correct 8 ms 2480 KB Output is correct
16 Correct 21 ms 2480 KB Output is correct
17 Correct 56 ms 3436 KB Output is correct
18 Correct 31 ms 3436 KB Output is correct
19 Correct 3 ms 3436 KB Output is correct
20 Correct 2 ms 3436 KB Output is correct
21 Correct 2 ms 3436 KB Output is correct
22 Correct 4 ms 3436 KB Output is correct
23 Correct 3 ms 3436 KB Output is correct
24 Correct 3 ms 3436 KB Output is correct
25 Correct 2 ms 3436 KB Output is correct
26 Correct 3 ms 3436 KB Output is correct
27 Correct 3 ms 3436 KB Output is correct
28 Correct 2 ms 3436 KB Output is correct
29 Correct 3 ms 3436 KB Output is correct
30 Correct 2 ms 3436 KB Output is correct
31 Correct 3 ms 3436 KB Output is correct
32 Correct 4 ms 3436 KB Output is correct
33 Correct 4 ms 3436 KB Output is correct
34 Correct 23 ms 3436 KB Output is correct
35 Correct 48 ms 3436 KB Output is correct
36 Correct 61 ms 3708 KB Output is correct
37 Correct 249 ms 3708 KB Output is correct
38 Correct 285 ms 3836 KB Output is correct
39 Correct 36 ms 3836 KB Output is correct
40 Correct 3 ms 3836 KB Output is correct
41 Correct 43 ms 3836 KB Output is correct
42 Correct 57 ms 3836 KB Output is correct
43 Correct 11 ms 3836 KB Output is correct
44 Correct 56 ms 3836 KB Output is correct
45 Correct 84 ms 3836 KB Output is correct
46 Correct 58 ms 3836 KB Output is correct
47 Correct 27 ms 3836 KB Output is correct
48 Correct 4 ms 3836 KB Output is correct
49 Correct 217 ms 3836 KB Output is correct
50 Correct 73 ms 3836 KB Output is correct
51 Correct 110 ms 3836 KB Output is correct
52 Correct 99 ms 3836 KB Output is correct
53 Correct 60 ms 3836 KB Output is correct
54 Correct 271 ms 3836 KB Output is correct
55 Correct 48 ms 3836 KB Output is correct
56 Correct 96 ms 3836 KB Output is correct
57 Correct 60 ms 3836 KB Output is correct
58 Correct 1042 ms 3836 KB Output is correct
59 Correct 1028 ms 3836 KB Output is correct
60 Correct 1002 ms 3836 KB Output is correct
61 Correct 1169 ms 3836 KB Output is correct
62 Correct 1051 ms 3836 KB Output is correct
63 Correct 1151 ms 3836 KB Output is correct
64 Correct 1053 ms 3836 KB Output is correct
65 Correct 2 ms 3836 KB Output is correct
66 Correct 3 ms 3836 KB Output is correct
67 Correct 1069 ms 5876 KB Output is correct
68 Correct 1037 ms 8168 KB Output is correct
69 Correct 922 ms 9764 KB Output is correct
70 Correct 971 ms 12136 KB Output is correct
71 Correct 929 ms 14292 KB Output is correct
72 Correct 984 ms 16336 KB Output is correct
73 Correct 946 ms 18328 KB Output is correct
74 Correct 1031 ms 20868 KB Output is correct
75 Correct 979 ms 22840 KB Output is correct
76 Correct 1046 ms 25208 KB Output is correct
77 Correct 194 ms 27836 KB Output is correct
78 Correct 70 ms 29480 KB Output is correct
79 Correct 134 ms 31420 KB Output is correct
80 Correct 140 ms 33580 KB Output is correct
81 Correct 115 ms 35364 KB Output is correct
82 Correct 99 ms 38032 KB Output is correct
83 Correct 75 ms 39812 KB Output is correct
84 Correct 615 ms 42404 KB Output is correct
85 Correct 1084 ms 44968 KB Output is correct
86 Correct 4 ms 44968 KB Output is correct
87 Correct 2 ms 44968 KB Output is correct
88 Correct 1067 ms 47424 KB Output is correct
89 Correct 230 ms 47424 KB Output is correct
90 Correct 2 ms 47424 KB Output is correct