Submission #667818

# Submission time Handle Problem Language Result Execution time Memory
667818 2022-12-02T06:00:03 Z Kaztaev_Alisher Chessboard (IZhO18_chessboard) C++17
70 / 100
226 ms 2652 KB
//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")

#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size
#define cl clear
#define ins insert
#define ers erase
#define pii pair < int , int >
#define pll pair< long long  , long long >
#define all(x) x.begin() , x.end()
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define tostr(x) to_string(x)
#define tonum(s) atoi(s.c_str())
#define seon(x) setprecision(x)
#define bpop(x) __builtin_popcount(x)
#define deb(x) cerr << #x  << " = " << x << endl;
#define int ll

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const double PI = 3.14159265;

const ll N = 1e6+5;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;

using namespace std;

int n;
bool u[N];
vector<int> v;
int cnt1[N] , cnt11[N];
void solve(){
	ll k;
	cin >> n >> k;
	ll mn = INF;
	for(int i = 1; i <= sqrtl(n); i++) {
		if(n % i == 0){
			v.pb(i); 
			if(i > 1) v.pb(n/i);
		}
	}
	for(int i = 1; i <= k; i++){
		int x , y , x1 , y1;
		cin >> x >> y >> x1 >> y1;
		x--;
		y--;
		for(int i = 0; i < v.sz(); i++){
			if((x/v[i])%2 == (y/v[i])%2) cnt1[i]++;
			else cnt11[i]++;
		}		
	}
	for(int i = 0; i < v.sz(); i++){
		ll ob = (n*n)/(v[i]*v[i]);
		mn = min(mn , (ob+1)/2*v[i]*v[i] - cnt1[i] + cnt11[i]);
		mn = min(mn , ob/2*v[i]*v[i] - cnt11[i] + cnt1[i]);
	}
	cout << mn <<"\n";
}
signed main(){
	ios;
	solve();
	return 0;
}
/*
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 'void solve()':
chessboard.cpp:57:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   for(int i = 0; i < v.sz(); i++){
      |                  ~~^~~~~~~~
chessboard.cpp:62:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |  for(int i = 0; i < v.sz(); i++){
      |                 ~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 340 KB Output is correct
2 Correct 8 ms 340 KB Output is correct
3 Correct 15 ms 352 KB Output is correct
4 Correct 17 ms 344 KB Output is correct
5 Correct 21 ms 340 KB Output is correct
6 Correct 10 ms 344 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 10 ms 348 KB Output is correct
9 Correct 26 ms 340 KB Output is correct
10 Correct 14 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 224 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 224 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 7 ms 340 KB Output is correct
17 Correct 21 ms 344 KB Output is correct
18 Correct 32 ms 340 KB Output is correct
19 Correct 52 ms 340 KB Output is correct
20 Correct 59 ms 340 KB Output is correct
21 Correct 18 ms 344 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 15 ms 348 KB Output is correct
24 Correct 23 ms 348 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 22 ms 340 KB Output is correct
27 Correct 30 ms 348 KB Output is correct
28 Correct 25 ms 344 KB Output is correct
29 Correct 8 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 340 KB Output is correct
2 Correct 8 ms 340 KB Output is correct
3 Correct 15 ms 352 KB Output is correct
4 Correct 17 ms 344 KB Output is correct
5 Correct 21 ms 340 KB Output is correct
6 Correct 10 ms 344 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 10 ms 348 KB Output is correct
9 Correct 26 ms 340 KB Output is correct
10 Correct 14 ms 348 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 224 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 7 ms 340 KB Output is correct
27 Correct 21 ms 344 KB Output is correct
28 Correct 32 ms 340 KB Output is correct
29 Correct 52 ms 340 KB Output is correct
30 Correct 59 ms 340 KB Output is correct
31 Correct 18 ms 344 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 15 ms 348 KB Output is correct
34 Correct 23 ms 348 KB Output is correct
35 Correct 3 ms 340 KB Output is correct
36 Correct 22 ms 340 KB Output is correct
37 Correct 30 ms 348 KB Output is correct
38 Correct 25 ms 344 KB Output is correct
39 Correct 8 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 54 ms 2184 KB Output is correct
42 Correct 31 ms 2504 KB Output is correct
43 Correct 40 ms 2228 KB Output is correct
44 Correct 30 ms 2492 KB Output is correct
45 Correct 29 ms 2624 KB Output is correct
46 Correct 60 ms 2488 KB Output is correct
47 Correct 27 ms 2360 KB Output is correct
48 Correct 34 ms 2376 KB Output is correct
49 Correct 29 ms 2236 KB Output is correct
50 Correct 198 ms 2492 KB Output is correct
51 Correct 214 ms 2652 KB Output is correct
52 Correct 206 ms 2368 KB Output is correct
53 Correct 209 ms 2620 KB Output is correct
54 Correct 196 ms 2380 KB Output is correct
55 Correct 226 ms 2620 KB Output is correct
56 Correct 194 ms 2380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 18 ms 340 KB Output is correct
10 Correct 8 ms 340 KB Output is correct
11 Correct 15 ms 352 KB Output is correct
12 Correct 17 ms 344 KB Output is correct
13 Correct 21 ms 340 KB Output is correct
14 Correct 10 ms 344 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 10 ms 348 KB Output is correct
17 Correct 26 ms 340 KB Output is correct
18 Correct 14 ms 348 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 224 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 7 ms 340 KB Output is correct
35 Correct 21 ms 344 KB Output is correct
36 Correct 32 ms 340 KB Output is correct
37 Correct 52 ms 340 KB Output is correct
38 Correct 59 ms 340 KB Output is correct
39 Correct 18 ms 344 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 15 ms 348 KB Output is correct
42 Correct 23 ms 348 KB Output is correct
43 Correct 3 ms 340 KB Output is correct
44 Correct 22 ms 340 KB Output is correct
45 Correct 30 ms 348 KB Output is correct
46 Correct 25 ms 344 KB Output is correct
47 Correct 8 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 54 ms 2184 KB Output is correct
50 Correct 31 ms 2504 KB Output is correct
51 Correct 40 ms 2228 KB Output is correct
52 Correct 30 ms 2492 KB Output is correct
53 Correct 29 ms 2624 KB Output is correct
54 Correct 60 ms 2488 KB Output is correct
55 Correct 27 ms 2360 KB Output is correct
56 Correct 34 ms 2376 KB Output is correct
57 Correct 29 ms 2236 KB Output is correct
58 Correct 198 ms 2492 KB Output is correct
59 Correct 214 ms 2652 KB Output is correct
60 Correct 206 ms 2368 KB Output is correct
61 Correct 209 ms 2620 KB Output is correct
62 Correct 196 ms 2380 KB Output is correct
63 Correct 226 ms 2620 KB Output is correct
64 Correct 194 ms 2380 KB Output is correct
65 Correct 1 ms 340 KB Output is correct
66 Incorrect 0 ms 340 KB Output isn't correct
67 Halted 0 ms 0 KB -