Submission #93092

# Submission time Handle Problem Language Result Execution time Memory
93092 2019-01-06T12:26:04 Z Makhsud Chessboard (IZhO18_chessboard) C++17
47 / 100
147 ms 504 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll n, k, x, y, xx, yy;
ll mn = INT_MAX;

ll ch ( ll del ) {
	ll ans = 0;
	if ( del == 1 ) {
		return (n*n)/2;
	}
	for ( int i = 1; i <= (n/del); i ++ ) {
		if ( i % 2 == 1 ) {
			ans += (del*del) * ( (n/del) / 2 );
		}
		else {
			ans += (del*del) * ( ( ( n/del )+1) / 2 );
		}
	}
	return ans;
}
ll a[5][5];
void subt2()
{
	for ( int i = 1; i <= k; i ++ ) {
		cin >> x >> y >> xx >> yy;
		a[x%2][y%2]++;
	}
	ll a1 = 0, a2 = 0;
	for ( int i = 1; i <= n; i ++ ){
		if ( i % 2 == 1 ) {
			a1 += (n/2);
			a2 += ((n+1)/2);
		}
		else {
			a2 += (n/2);
			a1 += ((n+1)/2);
		}
	}
	//a1 = (n*n) / 2;
	//a2 = a1 + 1;

	a2 = a2 - (a[1][1] + a[0][0]);
	a2 = a2 + (a[1][0] + a[0][1]);

	a1 = a1 - (a[1][0] + a[0][1]);
	a1 = a1 + (a[1][1] + a[0][0]);

	cout << min ( a1 ,a2 );
}
ll d[50000][5][5];
vector<ll>divs;
void subt3()
{
	for ( int i = 1; i < n; i ++ ){
		if ( n % i == 0 ){
			divs.push_back((ll)i);
		}
	}
	for ( int i = 1; i <= k; i ++ ) {
		cin >> x >> y >> xx >> yy;
		for ( auto e: divs ) {
			ll c, r;
			r = ( x / e ) + ((x % e) && 1 );
			c = ( y / e ) + ((y % e) && 1 );
			d[e][r%2][c%2] ++;
		}
	}
	ll cnt1 = 0, cnt2 = 0, mn = INT_MAX;
	for ( auto e: divs ){
		cnt1 = cnt2 = 0;
		for ( int i = 1; i <= n/e; i ++ ) {
			if ( i % 2 == 1 ) {
				cnt1 += ( (e*e) * ( ( n / e ) / 2 ) );
				cnt2 += ( (e*e) * ( ( ( n / e ) +1 ) / 2 ) );
			} else {
				cnt1 += ( (e*e) * ( ( ( n / e ) +1 ) / 2 ) );
				cnt2 += ( (e*e) * ( ( n / e ) / 2 ) );
			}
		}
		cnt1 += (d[e][1][1] + d[e][0][0]);
		cnt1 -= (d[e][1][0] + d[e][0][1]);

		cnt2 += (d[e][1][0] + d[e][0][1]);
		cnt2 -= (d[e][1][1] + d[e][0][0]);
		mn = min( mn, min( cnt1, cnt2 ) );
	}
	cout << mn;
}

int main()
{
	cin >> n >> k;
	ll cnt = 0;
	for ( int i = 1; i <= n; i ++ )
		if ( n % i == 0 ) cnt ++;

	if ( cnt == 2 ){
		subt2();
		return 0;
	}

	if ( k != 0 ) {
		subt3();
		return 0;
	}

	for ( int i = 1; i < n; i ++ ) {
		if ( n % i == 0 ) {
			ll an = ch(i);
			mn = min ( mn, an );
		}
	}
	cout << mn;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 256 KB Output is correct
2 Correct 18 ms 256 KB Output is correct
3 Correct 46 ms 376 KB Output is correct
4 Correct 44 ms 376 KB Output is correct
5 Correct 62 ms 256 KB Output is correct
6 Correct 40 ms 360 KB Output is correct
7 Correct 10 ms 256 KB Output is correct
8 Correct 42 ms 376 KB Output is correct
9 Correct 102 ms 376 KB Output is correct
10 Correct 57 ms 392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 296 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 3 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 296 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 3 ms 256 KB Output is correct
16 Correct 26 ms 364 KB Output is correct
17 Correct 70 ms 356 KB Output is correct
18 Correct 92 ms 292 KB Output is correct
19 Correct 130 ms 376 KB Output is correct
20 Correct 147 ms 504 KB Output is correct
21 Correct 70 ms 256 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 44 ms 376 KB Output is correct
24 Correct 81 ms 256 KB Output is correct
25 Correct 10 ms 376 KB Output is correct
26 Correct 53 ms 504 KB Output is correct
27 Correct 67 ms 408 KB Output is correct
28 Correct 86 ms 376 KB Output is correct
29 Correct 29 ms 256 KB Output is correct
30 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 256 KB Output is correct
2 Correct 18 ms 256 KB Output is correct
3 Correct 46 ms 376 KB Output is correct
4 Correct 44 ms 376 KB Output is correct
5 Correct 62 ms 256 KB Output is correct
6 Correct 40 ms 360 KB Output is correct
7 Correct 10 ms 256 KB Output is correct
8 Correct 42 ms 376 KB Output is correct
9 Correct 102 ms 376 KB Output is correct
10 Correct 57 ms 392 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 296 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 3 ms 256 KB Output is correct
26 Correct 26 ms 364 KB Output is correct
27 Correct 70 ms 356 KB Output is correct
28 Correct 92 ms 292 KB Output is correct
29 Correct 130 ms 376 KB Output is correct
30 Correct 147 ms 504 KB Output is correct
31 Correct 70 ms 256 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 44 ms 376 KB Output is correct
34 Correct 81 ms 256 KB Output is correct
35 Correct 10 ms 376 KB Output is correct
36 Correct 53 ms 504 KB Output is correct
37 Correct 67 ms 408 KB Output is correct
38 Correct 86 ms 376 KB Output is correct
39 Correct 29 ms 256 KB Output is correct
40 Correct 4 ms 256 KB Output is correct
41 Incorrect 139 ms 476 KB Output isn't correct
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 71 ms 256 KB Output is correct
10 Correct 18 ms 256 KB Output is correct
11 Correct 46 ms 376 KB Output is correct
12 Correct 44 ms 376 KB Output is correct
13 Correct 62 ms 256 KB Output is correct
14 Correct 40 ms 360 KB Output is correct
15 Correct 10 ms 256 KB Output is correct
16 Correct 42 ms 376 KB Output is correct
17 Correct 102 ms 376 KB Output is correct
18 Correct 57 ms 392 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 256 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 256 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 2 ms 256 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 2 ms 256 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 2 ms 296 KB Output is correct
32 Correct 2 ms 256 KB Output is correct
33 Correct 3 ms 256 KB Output is correct
34 Correct 26 ms 364 KB Output is correct
35 Correct 70 ms 356 KB Output is correct
36 Correct 92 ms 292 KB Output is correct
37 Correct 130 ms 376 KB Output is correct
38 Correct 147 ms 504 KB Output is correct
39 Correct 70 ms 256 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 44 ms 376 KB Output is correct
42 Correct 81 ms 256 KB Output is correct
43 Correct 10 ms 376 KB Output is correct
44 Correct 53 ms 504 KB Output is correct
45 Correct 67 ms 408 KB Output is correct
46 Correct 86 ms 376 KB Output is correct
47 Correct 29 ms 256 KB Output is correct
48 Correct 4 ms 256 KB Output is correct
49 Incorrect 139 ms 476 KB Output isn't correct
50 Halted 0 ms 0 KB -