#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define low_b lower_bound
#define up_b upper_bound
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
const int N = 1e+5 + 5;
pair < pair < int, int >, pair < int, int > > a[N];
ll ans = LLONG_MAX;
int n, k;
void solve(int v){
ll d = n / v;
if(d % 2 == 0){
ll res = (d / 2) * d * v * v;
for(int i = 1; i <= k; i++){
int x = a[i].x.x;
int y = a[i].x.y;
if(((x / v) - (x % v == 0)) % 2 == 0){
if(((y / v) - (y % v == 0)) % 2 == 1)res++;
else res--;
}
else{
if(((y / v) - (y % v == 0)) % 2 == 1)res--;
else res++;
}
}
ans = min(ans, res);
}
else{
ll l = ((d / 2) * (d / 2) + (d / 2 + 1) * (d / 2) + 1) * v * v;
ll r = ((d / 2) * (d / 2 + 1) + (d / 2 + 1) * (d / 2)) * v * v;
for(int i = 1; i <= k; i++){
int x = a[i].x.x;
int y = a[i].x.y;
if(((x / v) - (x % v == 0)) % 2 == 0){
if(((y / v) - (y % v == 0)) % 2 == 1)r--, l++;
else l--, r++;
}
else{
if(((y / v) - (y % v == 0)) % 2 == 1)r++, l--;
else r--, l++;
}
}
ans = min(ans, min(l, r));
}
}
int main(){
cin >> n >> k;
for(int i = 1; i <= k; i++){
cin >> a[i].x.x >> a[i].x.y >> a[i].y.x >> a[i].y.y;
}
solve(1);
for(int i = 2; i * i <= n; i++){
if(n % i == 0){
solve(i);
solve(n / i);
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Incorrect |
2 ms |
356 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
102 ms |
1328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
102 ms |
1328 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Incorrect |
2 ms |
356 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |