This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define adiyer(); ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) (x.begin(), x.end())
#define pb push_back
#define int long long
typedef long long ll;
using namespace std;
const int N = 1e5 + 11;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 11;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
ll n, m;
ll ax[N], bx[N], ay[N], by[N];
vector < ll > d;
bool check(ll x, ll y, ll sz){
ll a = x % (sz * 2);
ll b = y % (sz * 2);
a = bool(1 <= a && a <= sz);
b = bool(1 <= b && b <= sz);
// cout << x << ' ' << y << ' ' << a << ' ' << b << ' ' << sz << ' ' << ((a + b) & 1) << '\n';
return ((a + b) & 1);
}
void solve(){
cin >> n >> m;
for(int i = 1; i <= m; i++) cin >> ax[i] >> ay[i] >> bx[i] >> by[i];
for(int i = 1; i < n; i++){
if(n % i == 0){
d.pb(i);
}
}
ll mn = inf;
for(int sz : d){
ll cur1 = ((n / sz) * (n / sz) / 2) * (sz * sz);
ll cur2 = ((n / sz) * (n / sz) - ((n / sz) * (n / sz) / 2)) * (sz * sz);
cur1 -= m, cur2 -= m;
for(int i = 1; i <= m; i++){
if(!check(ax[i], ay[i], sz)) cur1 += 2;
else cur2 += 2;
}
// cout << sz << ' ' << cur1 << ' ' << cur2 << '\n';
mn = min(mn, min(cur1, cur2));
}
cout << mn;
}
const bool Cases = 0;
signed main(){
adiyer();
int CS = 1;
if(Cases) cin >> CS;
while(CS--) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |