Submission #497988

# Submission time Handle Problem Language Result Execution time Memory
497988 2021-12-24T08:10:31 Z vinnipuh01 Chessboard (IZhO18_chessboard) C++17
16 / 100
87 ms 3032 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 num = 0;
	num = x * y;
	int a, b;
	a = num / 2 + num % 2;
	return a;
}

int f1( int x, int y, int r ) {
	int num = 0, a, b;
	num = x * y;
	b = num / 2;
	return b;
}
	
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 );
		num -= sum;
		num += mx;
		ans -= mx;
		ans += sum;
	}
//	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: In function 'long long int ff(long long int, long long int, long long int)':
chessboard.cpp:52:9: warning: unused variable 'b' [-Wunused-variable]
   52 |  int a, b;
      |         ^
chessboard.cpp: In function 'long long int f1(long long int, long long int, long long int)':
chessboard.cpp:58:15: warning: unused variable 'a' [-Wunused-variable]
   58 |  int num = 0, a, b;
      |               ^
chessboard.cpp: At global scope:
chessboard.cpp:86:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   86 | main () {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 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 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 2140 KB Output is correct
2 Correct 17 ms 716 KB Output is correct
3 Correct 40 ms 1484 KB Output is correct
4 Correct 41 ms 1704 KB Output is correct
5 Correct 53 ms 1916 KB Output is correct
6 Correct 35 ms 1320 KB Output is correct
7 Correct 7 ms 460 KB Output is correct
8 Correct 35 ms 1356 KB Output is correct
9 Correct 87 ms 3032 KB Output is correct
10 Correct 49 ms 1844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 64 ms 2140 KB Output is correct
2 Correct 17 ms 716 KB Output is correct
3 Correct 40 ms 1484 KB Output is correct
4 Correct 41 ms 1704 KB Output is correct
5 Correct 53 ms 1916 KB Output is correct
6 Correct 35 ms 1320 KB Output is correct
7 Correct 7 ms 460 KB Output is correct
8 Correct 35 ms 1356 KB Output is correct
9 Correct 87 ms 3032 KB Output is correct
10 Correct 49 ms 1844 KB Output is correct
11 Incorrect 0 ms 204 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 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 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 64 ms 2140 KB Output is correct
10 Correct 17 ms 716 KB Output is correct
11 Correct 40 ms 1484 KB Output is correct
12 Correct 41 ms 1704 KB Output is correct
13 Correct 53 ms 1916 KB Output is correct
14 Correct 35 ms 1320 KB Output is correct
15 Correct 7 ms 460 KB Output is correct
16 Correct 35 ms 1356 KB Output is correct
17 Correct 87 ms 3032 KB Output is correct
18 Correct 49 ms 1844 KB Output is correct
19 Incorrect 0 ms 204 KB Output isn't correct
20 Halted 0 ms 0 KB -