Submission #498038

# Submission time Handle Problem Language Result Execution time Memory
498038 2021-12-24T09:56:23 Z vinnipuh01 Chessboard (IZhO18_chessboard) C++17
100 / 100
1323 ms 3652 KB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long

using namespace std;

const long long oo = 1000000000000000000;

long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;


/*
    ViHHiPuh

   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))


    cout << fixed << setprecision(6) << x;

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    freopen ( "sum.in", "r", stdin )
*/

int n, m;
int x[ 100001 ], y[ 100001 ], xx[ 100001 ], yy[ 100001 ];
	
int ff( int x, int y, int r ) {
	int sum, num, ans, mx;
	sum = x / r;
	num = ( sum + 1 ) / 2;
	num *= r;
	if ( sum % 2 == 0 )
		num += x % r;
	mx = y / r;
	ans = ( mx + 1 ) / 2;
	ans *= r;
	if ( mx % 2 == 0 )
		ans += y % r;
	return ans * num + ( ( x - num ) * ( y - ans ) );
}

int f1( int x, int y, int  r ) {
	int sum, num, ans, mx;
	sum = x / r;
	num = ( sum + 1 ) / 2;
	num *= r;
	if ( sum % 2 == 0 )
		num += x % r;
	mx = y / r;
	ans = ( mx ) / 2;
	ans *= r;
	if ( mx % 2 )
		ans += y % r;
	return ans * num + ( ( x - num ) * ( y - ans ) );
}
	
int f( int x1 ) {
	sum = ( n * n ) / ( x1 * x1 );
	ans = sum / 2;
	num = sum / 2;
	if ( sum % 2 )
		num ++;
	ans = ans * ( x1 * x1 );
	num = num * ( x1 * x1 );
	sum = 0;
	int mx = 0;
	for ( int i = 1; i <= m; i ++ ) {
		sum = ff( xx[ i ], yy[ i ], x1 ) + ff( x[ i ] - 1, y[ i ] - 1, x1 ) - ff( xx[ i ], y[ i ] - 1, x1 ) - ff( x[ i ] - 1, yy[ i ], x1 );
		mx = f1( xx[ i ], yy[ i ], x1 ) + f1( x[ i ] - 1, y[ i ] - 1, x1 ) - f1( xx[ i ], y[ i ] - 1, x1 ) - f1( x[ i ] - 1, yy[ i ], x1 );
		ans -= mx;
		num += mx;
		num -= sum;
		ans += sum;
//		cout << i << " - " << ans << " " << num << "\n";
	}
//	cout << x1 << " " << ans << " " << num << "\n";
	return min( ans, num );
}

main () {
	cin >> n >> m;
	for ( int i = 1; i <= m; i ++ ) {
		cin >> x[ i ] >> y[ i ] >> xx[ i ] >> yy[ i ];
	}
	mn = f( 1 );
	int sqr = sqrt( n );
	for ( int i = 2; i <= sqr; i ++ ) {
		if ( n % i == 0 ) {
			mn = min( mn, min( f( i ), f( n / i ) ) );
		}
	}
	cout << mn;
}

/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
*/

Compilation message

chessboard.cpp:102:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
  102 | main () {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 2224 KB Output is correct
2 Correct 18 ms 872 KB Output is correct
3 Correct 45 ms 1496 KB Output is correct
4 Correct 46 ms 1788 KB Output is correct
5 Correct 63 ms 2100 KB Output is correct
6 Correct 41 ms 1384 KB Output is correct
7 Correct 9 ms 568 KB Output is correct
8 Correct 43 ms 1548 KB Output is correct
9 Correct 100 ms 3132 KB Output is correct
10 Correct 61 ms 1928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 28 ms 1264 KB Output is correct
17 Correct 72 ms 3012 KB Output is correct
18 Correct 110 ms 3488 KB Output is correct
19 Correct 278 ms 3252 KB Output is correct
20 Correct 341 ms 3652 KB Output is correct
21 Correct 73 ms 3012 KB Output is correct
22 Correct 2 ms 304 KB Output is correct
23 Correct 63 ms 1744 KB Output is correct
24 Correct 96 ms 3272 KB Output is correct
25 Correct 12 ms 696 KB Output is correct
26 Correct 62 ms 2248 KB Output is correct
27 Correct 86 ms 2608 KB Output is correct
28 Correct 106 ms 3464 KB Output is correct
29 Correct 30 ms 1532 KB Output is correct
30 Correct 3 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 68 ms 2224 KB Output is correct
2 Correct 18 ms 872 KB Output is correct
3 Correct 45 ms 1496 KB Output is correct
4 Correct 46 ms 1788 KB Output is correct
5 Correct 63 ms 2100 KB Output is correct
6 Correct 41 ms 1384 KB Output is correct
7 Correct 9 ms 568 KB Output is correct
8 Correct 43 ms 1548 KB Output is correct
9 Correct 100 ms 3132 KB Output is correct
10 Correct 61 ms 1928 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 304 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 28 ms 1264 KB Output is correct
27 Correct 72 ms 3012 KB Output is correct
28 Correct 110 ms 3488 KB Output is correct
29 Correct 278 ms 3252 KB Output is correct
30 Correct 341 ms 3652 KB Output is correct
31 Correct 73 ms 3012 KB Output is correct
32 Correct 2 ms 304 KB Output is correct
33 Correct 63 ms 1744 KB Output is correct
34 Correct 96 ms 3272 KB Output is correct
35 Correct 12 ms 696 KB Output is correct
36 Correct 62 ms 2248 KB Output is correct
37 Correct 86 ms 2608 KB Output is correct
38 Correct 106 ms 3464 KB Output is correct
39 Correct 30 ms 1532 KB Output is correct
40 Correct 3 ms 440 KB Output is correct
41 Correct 271 ms 3076 KB Output is correct
42 Correct 127 ms 3420 KB Output is correct
43 Correct 169 ms 3176 KB Output is correct
44 Correct 120 ms 3296 KB Output is correct
45 Correct 109 ms 3444 KB Output is correct
46 Correct 296 ms 3336 KB Output is correct
47 Correct 98 ms 3112 KB Output is correct
48 Correct 147 ms 3204 KB Output is correct
49 Correct 120 ms 3084 KB Output is correct
50 Correct 1163 ms 3324 KB Output is correct
51 Correct 1240 ms 3508 KB Output is correct
52 Correct 1151 ms 3304 KB Output is correct
53 Correct 1221 ms 3488 KB Output is correct
54 Correct 1164 ms 3260 KB Output is correct
55 Correct 1257 ms 3604 KB Output is correct
56 Correct 1093 ms 3172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 304 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 68 ms 2224 KB Output is correct
10 Correct 18 ms 872 KB Output is correct
11 Correct 45 ms 1496 KB Output is correct
12 Correct 46 ms 1788 KB Output is correct
13 Correct 63 ms 2100 KB Output is correct
14 Correct 41 ms 1384 KB Output is correct
15 Correct 9 ms 568 KB Output is correct
16 Correct 43 ms 1548 KB Output is correct
17 Correct 100 ms 3132 KB Output is correct
18 Correct 61 ms 1928 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 304 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 332 KB Output is correct
32 Correct 2 ms 332 KB Output is correct
33 Correct 2 ms 332 KB Output is correct
34 Correct 28 ms 1264 KB Output is correct
35 Correct 72 ms 3012 KB Output is correct
36 Correct 110 ms 3488 KB Output is correct
37 Correct 278 ms 3252 KB Output is correct
38 Correct 341 ms 3652 KB Output is correct
39 Correct 73 ms 3012 KB Output is correct
40 Correct 2 ms 304 KB Output is correct
41 Correct 63 ms 1744 KB Output is correct
42 Correct 96 ms 3272 KB Output is correct
43 Correct 12 ms 696 KB Output is correct
44 Correct 62 ms 2248 KB Output is correct
45 Correct 86 ms 2608 KB Output is correct
46 Correct 106 ms 3464 KB Output is correct
47 Correct 30 ms 1532 KB Output is correct
48 Correct 3 ms 440 KB Output is correct
49 Correct 271 ms 3076 KB Output is correct
50 Correct 127 ms 3420 KB Output is correct
51 Correct 169 ms 3176 KB Output is correct
52 Correct 120 ms 3296 KB Output is correct
53 Correct 109 ms 3444 KB Output is correct
54 Correct 296 ms 3336 KB Output is correct
55 Correct 98 ms 3112 KB Output is correct
56 Correct 147 ms 3204 KB Output is correct
57 Correct 120 ms 3084 KB Output is correct
58 Correct 1163 ms 3324 KB Output is correct
59 Correct 1240 ms 3508 KB Output is correct
60 Correct 1151 ms 3304 KB Output is correct
61 Correct 1221 ms 3488 KB Output is correct
62 Correct 1164 ms 3260 KB Output is correct
63 Correct 1257 ms 3604 KB Output is correct
64 Correct 1093 ms 3172 KB Output is correct
65 Correct 1 ms 204 KB Output is correct
66 Correct 0 ms 204 KB Output is correct
67 Correct 1216 ms 3408 KB Output is correct
68 Correct 1185 ms 3396 KB Output is correct
69 Correct 1037 ms 3140 KB Output is correct
70 Correct 1173 ms 3200 KB Output is correct
71 Correct 1164 ms 3252 KB Output is correct
72 Correct 1131 ms 3188 KB Output is correct
73 Correct 1127 ms 3200 KB Output is correct
74 Correct 1182 ms 3384 KB Output is correct
75 Correct 1186 ms 3228 KB Output is correct
76 Correct 1214 ms 3528 KB Output is correct
77 Correct 245 ms 3504 KB Output is correct
78 Correct 113 ms 3244 KB Output is correct
79 Correct 178 ms 3136 KB Output is correct
80 Correct 188 ms 3252 KB Output is correct
81 Correct 169 ms 3052 KB Output is correct
82 Correct 167 ms 3508 KB Output is correct
83 Correct 132 ms 3140 KB Output is correct
84 Correct 761 ms 3576 KB Output is correct
85 Correct 1251 ms 3600 KB Output is correct
86 Correct 2 ms 204 KB Output is correct
87 Correct 1 ms 300 KB Output is correct
88 Correct 1323 ms 3600 KB Output is correct
89 Correct 250 ms 1064 KB Output is correct
90 Correct 1 ms 204 KB Output is correct