Submission #378635

# Submission time Handle Problem Language Result Execution time Memory
378635 2021-03-17T02:35:40 Z iris2617 Chessboard (IZhO18_chessboard) C++14
100 / 100
832 ms 4220 KB
#include<bits/stdc++.h>
#define int long long
#define matsuri pair<int,int>
#define iris 1000000007
using namespace std;

int xx1[100010],yy1[100010],xx2[100010],yy2[100010],n,k;

int cal(int x,int y,int shion)
{
	int a,b,res=0;
	a=x/shion;
	b=y/shion;
	if((a*b)&1)
		res+=shion*shion;
	if(a&1)
	{
		if((b+1)&1)
			res+=shion*(y%shion);
		else
			res-=shion*(y%shion);
	}
	if(b&1)
	{
		if((a+1)&1)
			res+=shion*(x%shion);
		else
			res-=shion*(x%shion);
	}
	if((a+b)&1)
		res-=(x%shion)*(y%shion);
	else
		res+=(x%shion)*(y%shion);
//	cout<<x<<' '<<y<<' '<<shion<<' '<<res<<'\n';
	return res;
}

int sana(int shion)
{
	int a,b,cnt,ouo,i;
	cnt=(n/shion)*(n/shion);
	a=cnt/2*shion*shion;
	b=(cnt+1)/2*shion*shion;
	ouo=0;
	for(i=0;i<k;i++)
	{
		ouo+=cal(xx2[i],yy2[i],shion)-cal(xx1[i]-1,yy2[i],shion)-cal(xx2[i],yy1[i]-1,shion)+cal(xx1[i]-1,yy1[i]-1,shion);
	}
//	cout<<shion<<' '<<a<<' '<<b<<' '<<a+ouo<<' '<<b-ouo<<'\n';
	return min(a+ouo, b-ouo);
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int i,ans=1e18;
	
	cin>>n>>k;
	for(i=0;i<k;i++)
	{
		cin>>xx1[i]>>yy1[i]>>xx2[i]>>yy2[i];
	}
	for(i=1;i<=sqrt(n);i++)
	{
		if(n%i==0)
		{
			ans=min(ans, sana(i));
			if(i>1)
				ans=min(ans, sana(n/i));
		}
	}
	cout<<ans<<'\n';
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 396 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 2284 KB Output is correct
2 Correct 11 ms 876 KB Output is correct
3 Correct 17 ms 1644 KB Output is correct
4 Correct 19 ms 1772 KB Output is correct
5 Correct 25 ms 2028 KB Output is correct
6 Correct 15 ms 1388 KB Output is correct
7 Correct 4 ms 624 KB Output is correct
8 Correct 23 ms 1388 KB Output is correct
9 Correct 39 ms 3180 KB Output is correct
10 Correct 22 ms 1900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 14 ms 1260 KB Output is correct
17 Correct 37 ms 2924 KB Output is correct
18 Correct 48 ms 3436 KB Output is correct
19 Correct 158 ms 3052 KB Output is correct
20 Correct 178 ms 3564 KB Output is correct
21 Correct 30 ms 2924 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 30 ms 1644 KB Output is correct
24 Correct 43 ms 3180 KB Output is correct
25 Correct 6 ms 620 KB Output is correct
26 Correct 28 ms 2156 KB Output is correct
27 Correct 42 ms 2540 KB Output is correct
28 Correct 47 ms 3308 KB Output is correct
29 Correct 13 ms 1388 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 2284 KB Output is correct
2 Correct 11 ms 876 KB Output is correct
3 Correct 17 ms 1644 KB Output is correct
4 Correct 19 ms 1772 KB Output is correct
5 Correct 25 ms 2028 KB Output is correct
6 Correct 15 ms 1388 KB Output is correct
7 Correct 4 ms 624 KB Output is correct
8 Correct 23 ms 1388 KB Output is correct
9 Correct 39 ms 3180 KB Output is correct
10 Correct 22 ms 1900 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 14 ms 1260 KB Output is correct
27 Correct 37 ms 2924 KB Output is correct
28 Correct 48 ms 3436 KB Output is correct
29 Correct 158 ms 3052 KB Output is correct
30 Correct 178 ms 3564 KB Output is correct
31 Correct 30 ms 2924 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 30 ms 1644 KB Output is correct
34 Correct 43 ms 3180 KB Output is correct
35 Correct 6 ms 620 KB Output is correct
36 Correct 28 ms 2156 KB Output is correct
37 Correct 42 ms 2540 KB Output is correct
38 Correct 47 ms 3308 KB Output is correct
39 Correct 13 ms 1388 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 145 ms 3052 KB Output is correct
42 Correct 51 ms 3308 KB Output is correct
43 Correct 87 ms 2924 KB Output is correct
44 Correct 50 ms 3180 KB Output is correct
45 Correct 42 ms 3436 KB Output is correct
46 Correct 160 ms 3308 KB Output is correct
47 Correct 37 ms 3052 KB Output is correct
48 Correct 69 ms 3052 KB Output is correct
49 Correct 48 ms 2924 KB Output is correct
50 Correct 717 ms 3180 KB Output is correct
51 Correct 754 ms 3564 KB Output is correct
52 Correct 709 ms 3308 KB Output is correct
53 Correct 742 ms 3436 KB Output is correct
54 Correct 700 ms 3436 KB Output is correct
55 Correct 775 ms 3564 KB Output is correct
56 Correct 688 ms 3180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 396 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 28 ms 2284 KB Output is correct
10 Correct 11 ms 876 KB Output is correct
11 Correct 17 ms 1644 KB Output is correct
12 Correct 19 ms 1772 KB Output is correct
13 Correct 25 ms 2028 KB Output is correct
14 Correct 15 ms 1388 KB Output is correct
15 Correct 4 ms 624 KB Output is correct
16 Correct 23 ms 1388 KB Output is correct
17 Correct 39 ms 3180 KB Output is correct
18 Correct 22 ms 1900 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 14 ms 1260 KB Output is correct
35 Correct 37 ms 2924 KB Output is correct
36 Correct 48 ms 3436 KB Output is correct
37 Correct 158 ms 3052 KB Output is correct
38 Correct 178 ms 3564 KB Output is correct
39 Correct 30 ms 2924 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 30 ms 1644 KB Output is correct
42 Correct 43 ms 3180 KB Output is correct
43 Correct 6 ms 620 KB Output is correct
44 Correct 28 ms 2156 KB Output is correct
45 Correct 42 ms 2540 KB Output is correct
46 Correct 47 ms 3308 KB Output is correct
47 Correct 13 ms 1388 KB Output is correct
48 Correct 2 ms 492 KB Output is correct
49 Correct 145 ms 3052 KB Output is correct
50 Correct 51 ms 3308 KB Output is correct
51 Correct 87 ms 2924 KB Output is correct
52 Correct 50 ms 3180 KB Output is correct
53 Correct 42 ms 3436 KB Output is correct
54 Correct 160 ms 3308 KB Output is correct
55 Correct 37 ms 3052 KB Output is correct
56 Correct 69 ms 3052 KB Output is correct
57 Correct 48 ms 2924 KB Output is correct
58 Correct 717 ms 3180 KB Output is correct
59 Correct 754 ms 3564 KB Output is correct
60 Correct 709 ms 3308 KB Output is correct
61 Correct 742 ms 3436 KB Output is correct
62 Correct 700 ms 3436 KB Output is correct
63 Correct 775 ms 3564 KB Output is correct
64 Correct 688 ms 3180 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Correct 751 ms 4220 KB Output is correct
68 Correct 755 ms 3948 KB Output is correct
69 Correct 665 ms 3512 KB Output is correct
70 Correct 722 ms 3820 KB Output is correct
71 Correct 724 ms 3744 KB Output is correct
72 Correct 703 ms 3692 KB Output is correct
73 Correct 680 ms 3564 KB Output is correct
74 Correct 736 ms 3948 KB Output is correct
75 Correct 718 ms 3744 KB Output is correct
76 Correct 762 ms 4052 KB Output is correct
77 Correct 140 ms 4076 KB Output is correct
78 Correct 52 ms 3820 KB Output is correct
79 Correct 93 ms 3628 KB Output is correct
80 Correct 99 ms 3692 KB Output is correct
81 Correct 90 ms 3564 KB Output is correct
82 Correct 77 ms 3948 KB Output is correct
83 Correct 63 ms 3572 KB Output is correct
84 Correct 468 ms 4076 KB Output is correct
85 Correct 801 ms 4156 KB Output is correct
86 Correct 1 ms 364 KB Output is correct
87 Correct 1 ms 364 KB Output is correct
88 Correct 832 ms 4148 KB Output is correct
89 Correct 163 ms 1516 KB Output is correct
90 Correct 1 ms 404 KB Output is correct