#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
/// toto -> 1
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define io \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define all(a) a.begin(),a.end()
#define rep(k,i,n) for(ll k=i;k<n;k++)
#define repp(k,i,n) for(ll k=n-1;k>=i;k--)
#define rech(k) for(char k='a';k<='z';k++)
#define SZ(a) (int)a.size()
#define MX(a) *max_element(all(a))
#define MN(a) *min_element(all(a))
#define SM(a) accumulate(all(a),0LL)
#define vi vector<int>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvi vector<vector<int>>
/// toto -> 2
const int mod = 1e9 + 7 , modd = 998244353;
typedef long long ll;
void F1(bool res) {
if(res) {
cout<<"Yes\n" ;
}
else {
cout<<"No\n" ;
}
}
struct mint{
ll val;
mint(int64_t v = 0) {
v %= mod;
if (v < 0) v += mod;
val = v;
}
mint& operator+=(const mint& other) {
val += other.val;
if (val >= mod) val -= mod;
return *this;
}
mint& operator-=(const mint& other) {
val += mod - other.val;
if (val >= mod) val -= mod;
return *this;
}
mint& operator*=(const mint& other) {
val = (int64_t)val * other.val % mod;
return *this;
}
mint& operator/=(const mint& other) {
return *this *= other.inv();
}
friend mint operator+(mint a, const mint& b) { return a += b; }
friend mint operator-(mint a, const mint& b) { return a -= b; }
friend mint operator*(mint a, const mint& b) { return a *= b; }
friend mint operator/(mint a, const mint& b) { return a /= b; }
mint pow(int64_t exp) const {
mint a = *this, res = 1;
while (exp > 0) {
if (exp & 1)
res *= a;
a *= a;
exp >>= 1;
}
return res;
}
mint inv() const {
assert(val != 0);
return pow(mod - 2);
}
friend ostream& operator<<(ostream& os, const mint& m) {
return os << m.val;
}
};
ll bp(ll n,ll m){
if(m == 0){
return 1;
}
if(m == 1){
return n%mod;
}
if(m%2==0){
return bp(n*n%mod,m/2)%mod;
}
return n*bp(n,m-1)%mod;
}
/// toto -> 3
const int N = 1e8 + 54, M = 33, inf = 1e9 + 99;
const ll inff = 5e18;
struct pi{
int x1,y1,x2,y2;
};
void solve(){
int n, k;
cin >> n >> k;
/// n in boleni olan lari elave edirik
vi v;
for(int i=1;i<n;i++){
if(n%i == 0){
v.pb(i);
}
}
vector<pi> a(k);
rep(i,0,k){
cin >> a[i].x1 >> a[i].y1 >> a[i].x2 >> a[i].y2;
}
ll res = inff;
for(auto &x : v){
ll tmp = (ll)(n/(2*x))*n*x;
if(n%(2*x) != 0){
tmp += ((n -1 + x + x)/(2*x))*x*x;
}
///cerr << "1 " << tmp << endl;
rep(i,0,k){
if(((a[i].x1 + x - 1) / x)%2 != ((a[i].y1 + x - 1) / x)%2){
tmp++;
}
else{
tmp--;
}
}
/// updateing
res = min(res , tmp);
tmp = (ll)(n/(2*x))*n*x;
if(n%(2*x) != 0){
tmp += (ll)(n/(2*x))*x*x;
}
///cerr << "2 " << tmp << endl;
rep(i,0,k){
if(((a[i].x1 + x - 1) / x)%2 == ((a[i].y1 + x - 1) / x)%2){
tmp++;
}
else{
tmp--;
}
}
/// updateing again
res = min(res , tmp);
}
assert(res < inff);
cout << res << endl;
}
int32_t main()
{
io;
ll t=1;
/// cin>>t;
rep(_,1,t+1)
{
cerr << "Start of test case " << _ << "\n";
///cout<<"Case #"<<_<<": ";
solve();
cerr << endl;
cerr << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
2720 KB |
Output is correct |
2 |
Correct |
5 ms |
860 KB |
Output is correct |
3 |
Correct |
11 ms |
1880 KB |
Output is correct |
4 |
Correct |
12 ms |
1884 KB |
Output is correct |
5 |
Correct |
15 ms |
2460 KB |
Output is correct |
6 |
Correct |
9 ms |
1624 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
10 ms |
1628 KB |
Output is correct |
9 |
Correct |
24 ms |
3932 KB |
Output is correct |
10 |
Correct |
14 ms |
2368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
7 ms |
1376 KB |
Output is correct |
17 |
Correct |
19 ms |
3152 KB |
Output is correct |
18 |
Correct |
29 ms |
3416 KB |
Output is correct |
19 |
Correct |
65 ms |
3164 KB |
Output is correct |
20 |
Correct |
71 ms |
3844 KB |
Output is correct |
21 |
Correct |
22 ms |
2908 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
15 ms |
1640 KB |
Output is correct |
24 |
Correct |
23 ms |
3164 KB |
Output is correct |
25 |
Correct |
4 ms |
728 KB |
Output is correct |
26 |
Correct |
15 ms |
2140 KB |
Output is correct |
27 |
Correct |
20 ms |
2396 KB |
Output is correct |
28 |
Correct |
30 ms |
3420 KB |
Output is correct |
29 |
Correct |
8 ms |
1372 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
2720 KB |
Output is correct |
2 |
Correct |
5 ms |
860 KB |
Output is correct |
3 |
Correct |
11 ms |
1880 KB |
Output is correct |
4 |
Correct |
12 ms |
1884 KB |
Output is correct |
5 |
Correct |
15 ms |
2460 KB |
Output is correct |
6 |
Correct |
9 ms |
1624 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
10 ms |
1628 KB |
Output is correct |
9 |
Correct |
24 ms |
3932 KB |
Output is correct |
10 |
Correct |
14 ms |
2368 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
7 ms |
1376 KB |
Output is correct |
27 |
Correct |
19 ms |
3152 KB |
Output is correct |
28 |
Correct |
29 ms |
3416 KB |
Output is correct |
29 |
Correct |
65 ms |
3164 KB |
Output is correct |
30 |
Correct |
71 ms |
3844 KB |
Output is correct |
31 |
Correct |
22 ms |
2908 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
15 ms |
1640 KB |
Output is correct |
34 |
Correct |
23 ms |
3164 KB |
Output is correct |
35 |
Correct |
4 ms |
728 KB |
Output is correct |
36 |
Correct |
15 ms |
2140 KB |
Output is correct |
37 |
Correct |
20 ms |
2396 KB |
Output is correct |
38 |
Correct |
30 ms |
3420 KB |
Output is correct |
39 |
Correct |
8 ms |
1372 KB |
Output is correct |
40 |
Correct |
1 ms |
348 KB |
Output is correct |
41 |
Incorrect |
60 ms |
3732 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
17 ms |
2720 KB |
Output is correct |
10 |
Correct |
5 ms |
860 KB |
Output is correct |
11 |
Correct |
11 ms |
1880 KB |
Output is correct |
12 |
Correct |
12 ms |
1884 KB |
Output is correct |
13 |
Correct |
15 ms |
2460 KB |
Output is correct |
14 |
Correct |
9 ms |
1624 KB |
Output is correct |
15 |
Correct |
2 ms |
604 KB |
Output is correct |
16 |
Correct |
10 ms |
1628 KB |
Output is correct |
17 |
Correct |
24 ms |
3932 KB |
Output is correct |
18 |
Correct |
14 ms |
2368 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
7 ms |
1376 KB |
Output is correct |
35 |
Correct |
19 ms |
3152 KB |
Output is correct |
36 |
Correct |
29 ms |
3416 KB |
Output is correct |
37 |
Correct |
65 ms |
3164 KB |
Output is correct |
38 |
Correct |
71 ms |
3844 KB |
Output is correct |
39 |
Correct |
22 ms |
2908 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
15 ms |
1640 KB |
Output is correct |
42 |
Correct |
23 ms |
3164 KB |
Output is correct |
43 |
Correct |
4 ms |
728 KB |
Output is correct |
44 |
Correct |
15 ms |
2140 KB |
Output is correct |
45 |
Correct |
20 ms |
2396 KB |
Output is correct |
46 |
Correct |
30 ms |
3420 KB |
Output is correct |
47 |
Correct |
8 ms |
1372 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Incorrect |
60 ms |
3732 KB |
Output isn't correct |
50 |
Halted |
0 ms |
0 KB |
- |