답안 #92979

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
92979 2019-01-06T09:34:25 Z Makhsud Chessboard (IZhO18_chessboard) C++17
31 / 100
2000 ms 62448 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll n, k, x, y, xx, yy;
ll d, 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;
	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) );
}
map < ll, map < ll, bool > > used;
ll NumOfPainted( ll s, ll e, ll de ) {
	ll num = 0;
	for ( int i = s; i <= s+de-1; i ++ ){
		for ( int j = e; j <= e+de-1; j ++ ) {
			if ( used[i][j] ) num ++;
		}
	}
	return num;
}
ll subt3( ll del )
{
	ll cnt1 = 0, cnt2 = 0, c=0, d=0;
	for ( int i = 1; i <= n; i += del ) {
		c ++;
		for ( int j = 1; j <= n; j += del ) {
			d ++;
			if ( (c % 2 == 1 && d % 2 == 0) || (c % 2 == 0 && d % 2 == 1) ) {
				cnt1 += ( (del*del) - NumOfPainted(i,j,del) );
				cnt2 += NumOfPainted(i,j,del);
			}
			if ( (c % 2 == 1 && d % 2 == 1) || (c % 2 == 0 && d % 2 == 0) ) {
				cnt1 += NumOfPainted(i,j,del);
				cnt2 += ( (del*del) - NumOfPainted(i,j,del) );
			}
		}
		d = 0;
	}
	return min(cnt1,cnt2);
}

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 ) {
		ll MN = INT_MAX;
		for ( int i = 1; i <= k; i ++ ) {
			cin >> x >> y >> xx >> yy;
			used[x][y] = true;
		}
		for ( int i = 1; i < n; i ++ ) {
			if ( n % i == 0 ) {
				ll an = subt3(i);
				//cout << an << '\n';
				MN = min (MN, an);
			}
		}
		cout << MN;
		return 0;
	}

	for ( int i = 1; i < n; i ++ ) {
		if ( n % i == 0 ) {
			ll an = ch(i);
			mn = min ( mn, an );
		}
	}
	cout << mn;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 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 380 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 632 KB Output is correct
2 Correct 19 ms 504 KB Output is correct
3 Correct 47 ms 504 KB Output is correct
4 Correct 45 ms 504 KB Output is correct
5 Correct 62 ms 632 KB Output is correct
6 Correct 41 ms 604 KB Output is correct
7 Correct 10 ms 508 KB Output is correct
8 Correct 41 ms 632 KB Output is correct
9 Correct 104 ms 504 KB Output is correct
10 Correct 59 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 760 KB Output is correct
2 Correct 6 ms 632 KB Output is correct
3 Correct 9 ms 760 KB Output is correct
4 Correct 8 ms 632 KB Output is correct
5 Correct 6 ms 632 KB Output is correct
6 Correct 6 ms 760 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 5 ms 508 KB Output is correct
9 Correct 6 ms 888 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 7 ms 632 KB Output is correct
15 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 760 KB Output is correct
2 Correct 6 ms 632 KB Output is correct
3 Correct 9 ms 760 KB Output is correct
4 Correct 8 ms 632 KB Output is correct
5 Correct 6 ms 632 KB Output is correct
6 Correct 6 ms 760 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 5 ms 508 KB Output is correct
9 Correct 6 ms 888 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 5 ms 632 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 6 ms 632 KB Output is correct
14 Correct 7 ms 632 KB Output is correct
15 Correct 4 ms 504 KB Output is correct
16 Correct 567 ms 57176 KB Output is correct
17 Correct 72 ms 472 KB Output is correct
18 Correct 828 ms 62448 KB Output is correct
19 Execution timed out 2062 ms 58332 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 632 KB Output is correct
2 Correct 19 ms 504 KB Output is correct
3 Correct 47 ms 504 KB Output is correct
4 Correct 45 ms 504 KB Output is correct
5 Correct 62 ms 632 KB Output is correct
6 Correct 41 ms 604 KB Output is correct
7 Correct 10 ms 508 KB Output is correct
8 Correct 41 ms 632 KB Output is correct
9 Correct 104 ms 504 KB Output is correct
10 Correct 59 ms 504 KB Output is correct
11 Correct 7 ms 760 KB Output is correct
12 Correct 6 ms 632 KB Output is correct
13 Correct 9 ms 760 KB Output is correct
14 Correct 8 ms 632 KB Output is correct
15 Correct 6 ms 632 KB Output is correct
16 Correct 6 ms 760 KB Output is correct
17 Correct 6 ms 760 KB Output is correct
18 Correct 5 ms 508 KB Output is correct
19 Correct 6 ms 888 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 5 ms 632 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 6 ms 632 KB Output is correct
24 Correct 7 ms 632 KB Output is correct
25 Correct 4 ms 504 KB Output is correct
26 Correct 567 ms 57176 KB Output is correct
27 Correct 72 ms 472 KB Output is correct
28 Correct 828 ms 62448 KB Output is correct
29 Execution timed out 2062 ms 58332 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 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 380 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 76 ms 632 KB Output is correct
10 Correct 19 ms 504 KB Output is correct
11 Correct 47 ms 504 KB Output is correct
12 Correct 45 ms 504 KB Output is correct
13 Correct 62 ms 632 KB Output is correct
14 Correct 41 ms 604 KB Output is correct
15 Correct 10 ms 508 KB Output is correct
16 Correct 41 ms 632 KB Output is correct
17 Correct 104 ms 504 KB Output is correct
18 Correct 59 ms 504 KB Output is correct
19 Correct 7 ms 760 KB Output is correct
20 Correct 6 ms 632 KB Output is correct
21 Correct 9 ms 760 KB Output is correct
22 Correct 8 ms 632 KB Output is correct
23 Correct 6 ms 632 KB Output is correct
24 Correct 6 ms 760 KB Output is correct
25 Correct 6 ms 760 KB Output is correct
26 Correct 5 ms 508 KB Output is correct
27 Correct 6 ms 888 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 5 ms 632 KB Output is correct
30 Correct 2 ms 256 KB Output is correct
31 Correct 6 ms 632 KB Output is correct
32 Correct 7 ms 632 KB Output is correct
33 Correct 4 ms 504 KB Output is correct
34 Correct 567 ms 57176 KB Output is correct
35 Correct 72 ms 472 KB Output is correct
36 Correct 828 ms 62448 KB Output is correct
37 Execution timed out 2062 ms 58332 KB Time limit exceeded
38 Halted 0 ms 0 KB -