#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
const int maxn=1e5+9;
struct rect{
int x1,y1,x2,y2;
}a[maxn];
long long cal(int len,bool odd){
if (!odd){
if (len%2==1)len--;
return (len-2)/2+1;
}
else {
if (len%2==0)len--;
return (len-1)/2+1;
}
}
long long x[2];
long long cal(int l,int r,bool odd){
if (odd){
if (r%2==0)r--;
if (l%2==0)l++;
if (l>r)return 0;
return (r-l)/2+1;
}
else {
if (r%2==1)r--;
if (l%2==1)l++;
if (l>r)return 0;
return (r-l)/2+1;
}
}
pair<long long,long long> solve(int x1, int y1,int i){
memset(x,0,sizeof(x));
if ((x1/i)==(y1/i)){
x[((x1+i-1)/i)%2]+=y1-x1+1;
//cout<<"yay";
}
else {
int len=(x1+i-1)/i;
//cerr<<len<<'\n';
x[len%2]+=(len)*i-x1+1;
x1=(len)*i+1;
x[((y1+i-1)/i)%2]+=(y1)%i;
y1-=(y1%i);
//cout<<x[0]<<" "<<y1<<'\n';
if (x1>y1)return {x[0],x[1]};
int l1=((x1+i-1)/i),l2=y1/i;
x[0]+=1ll*cal(l1,l2,0)*i;
x[1]+=1ll*cal(l1,l2,1)*i;
}
return {x[0],x[1]};
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("temp.INP","r",stdin);
//freopen("temp.OUT","w",stdout);
long long n;
int k;
cin>>n>>k;
for1(i,1,k)cin>>a[i].x1>>a[i].y1>>a[i].x2>>a[i].y2;
long long ans=n*n;
for1(i,1,n-1){
if (n%i!=0)continue;
long long len=n/i;
long long sum=cal(len,1)*cal(len,1)*i*i+cal(len,0)*cal(len,0)*i*i;
long long sum2=cal(len,1)*cal(len,0)*i*i+cal(len,0)*cal(len,1)*i*i;
for1(j,1,k){
int x1=a[j].x1,y1=a[j].y1,x2=a[j].x2,y2=a[j].y2;
pair<long long,long long>cordx=solve(x1,x2,i),cordy=solve(y1,y2,i);
sum-=cordx.fi*cordy.fi;
sum-=cordx.se*cordy.se;
sum+=cordx.fi*cordy.se;
sum+=cordx.se*cordy.fi;
sum2+=cordx.fi*cordy.fi;
sum2+=cordx.se*cordy.se;
sum2-=cordx.fi*cordy.se;
sum2-=cordx.se*cordy.fi;
}
ans=min(ans,sum);
ans=min(ans,sum2);
}
cout<<ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
2900 KB |
Output is correct |
2 |
Correct |
5 ms |
856 KB |
Output is correct |
3 |
Correct |
11 ms |
1880 KB |
Output is correct |
4 |
Correct |
14 ms |
1884 KB |
Output is correct |
5 |
Correct |
16 ms |
2392 KB |
Output is correct |
6 |
Correct |
10 ms |
1624 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
10 ms |
1624 KB |
Output is correct |
9 |
Correct |
27 ms |
3920 KB |
Output is correct |
10 |
Correct |
14 ms |
2528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
500 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
500 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
8 ms |
1112 KB |
Output is correct |
17 |
Correct |
20 ms |
2908 KB |
Output is correct |
18 |
Correct |
32 ms |
3420 KB |
Output is correct |
19 |
Correct |
91 ms |
3244 KB |
Output is correct |
20 |
Correct |
97 ms |
3416 KB |
Output is correct |
21 |
Correct |
19 ms |
2896 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
18 ms |
1628 KB |
Output is correct |
24 |
Correct |
28 ms |
3220 KB |
Output is correct |
25 |
Correct |
5 ms |
600 KB |
Output is correct |
26 |
Correct |
16 ms |
2136 KB |
Output is correct |
27 |
Correct |
24 ms |
2392 KB |
Output is correct |
28 |
Correct |
28 ms |
3340 KB |
Output is correct |
29 |
Correct |
10 ms |
1368 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
2900 KB |
Output is correct |
2 |
Correct |
5 ms |
856 KB |
Output is correct |
3 |
Correct |
11 ms |
1880 KB |
Output is correct |
4 |
Correct |
14 ms |
1884 KB |
Output is correct |
5 |
Correct |
16 ms |
2392 KB |
Output is correct |
6 |
Correct |
10 ms |
1624 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
10 ms |
1624 KB |
Output is correct |
9 |
Correct |
27 ms |
3920 KB |
Output is correct |
10 |
Correct |
14 ms |
2528 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
500 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
8 ms |
1112 KB |
Output is correct |
27 |
Correct |
20 ms |
2908 KB |
Output is correct |
28 |
Correct |
32 ms |
3420 KB |
Output is correct |
29 |
Correct |
91 ms |
3244 KB |
Output is correct |
30 |
Correct |
97 ms |
3416 KB |
Output is correct |
31 |
Correct |
19 ms |
2896 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
18 ms |
1628 KB |
Output is correct |
34 |
Correct |
28 ms |
3220 KB |
Output is correct |
35 |
Correct |
5 ms |
600 KB |
Output is correct |
36 |
Correct |
16 ms |
2136 KB |
Output is correct |
37 |
Correct |
24 ms |
2392 KB |
Output is correct |
38 |
Correct |
28 ms |
3340 KB |
Output is correct |
39 |
Correct |
10 ms |
1368 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
81 ms |
3672 KB |
Output is correct |
42 |
Correct |
32 ms |
3928 KB |
Output is correct |
43 |
Correct |
51 ms |
3736 KB |
Output is correct |
44 |
Correct |
33 ms |
4040 KB |
Output is correct |
45 |
Correct |
27 ms |
4224 KB |
Output is correct |
46 |
Correct |
90 ms |
4116 KB |
Output is correct |
47 |
Correct |
25 ms |
3664 KB |
Output is correct |
48 |
Correct |
41 ms |
3640 KB |
Output is correct |
49 |
Correct |
29 ms |
3664 KB |
Output is correct |
50 |
Correct |
390 ms |
3928 KB |
Output is correct |
51 |
Correct |
417 ms |
4304 KB |
Output is correct |
52 |
Correct |
385 ms |
4176 KB |
Output is correct |
53 |
Correct |
411 ms |
4176 KB |
Output is correct |
54 |
Correct |
381 ms |
3924 KB |
Output is correct |
55 |
Correct |
429 ms |
4696 KB |
Output is correct |
56 |
Correct |
371 ms |
3852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
18 ms |
2900 KB |
Output is correct |
10 |
Correct |
5 ms |
856 KB |
Output is correct |
11 |
Correct |
11 ms |
1880 KB |
Output is correct |
12 |
Correct |
14 ms |
1884 KB |
Output is correct |
13 |
Correct |
16 ms |
2392 KB |
Output is correct |
14 |
Correct |
10 ms |
1624 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
10 ms |
1624 KB |
Output is correct |
17 |
Correct |
27 ms |
3920 KB |
Output is correct |
18 |
Correct |
14 ms |
2528 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
500 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
8 ms |
1112 KB |
Output is correct |
35 |
Correct |
20 ms |
2908 KB |
Output is correct |
36 |
Correct |
32 ms |
3420 KB |
Output is correct |
37 |
Correct |
91 ms |
3244 KB |
Output is correct |
38 |
Correct |
97 ms |
3416 KB |
Output is correct |
39 |
Correct |
19 ms |
2896 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
18 ms |
1628 KB |
Output is correct |
42 |
Correct |
28 ms |
3220 KB |
Output is correct |
43 |
Correct |
5 ms |
600 KB |
Output is correct |
44 |
Correct |
16 ms |
2136 KB |
Output is correct |
45 |
Correct |
24 ms |
2392 KB |
Output is correct |
46 |
Correct |
28 ms |
3340 KB |
Output is correct |
47 |
Correct |
10 ms |
1368 KB |
Output is correct |
48 |
Correct |
1 ms |
344 KB |
Output is correct |
49 |
Correct |
81 ms |
3672 KB |
Output is correct |
50 |
Correct |
32 ms |
3928 KB |
Output is correct |
51 |
Correct |
51 ms |
3736 KB |
Output is correct |
52 |
Correct |
33 ms |
4040 KB |
Output is correct |
53 |
Correct |
27 ms |
4224 KB |
Output is correct |
54 |
Correct |
90 ms |
4116 KB |
Output is correct |
55 |
Correct |
25 ms |
3664 KB |
Output is correct |
56 |
Correct |
41 ms |
3640 KB |
Output is correct |
57 |
Correct |
29 ms |
3664 KB |
Output is correct |
58 |
Correct |
390 ms |
3928 KB |
Output is correct |
59 |
Correct |
417 ms |
4304 KB |
Output is correct |
60 |
Correct |
385 ms |
4176 KB |
Output is correct |
61 |
Correct |
411 ms |
4176 KB |
Output is correct |
62 |
Correct |
381 ms |
3924 KB |
Output is correct |
63 |
Correct |
429 ms |
4696 KB |
Output is correct |
64 |
Correct |
371 ms |
3852 KB |
Output is correct |
65 |
Correct |
1 ms |
344 KB |
Output is correct |
66 |
Correct |
0 ms |
344 KB |
Output is correct |
67 |
Incorrect |
454 ms |
4132 KB |
Output isn't correct |
68 |
Halted |
0 ms |
0 KB |
- |