이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define N 100050
#define f first
#define s second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
ll n, k, x[N], y[N], xf[N], yf[N];
long long ans = (2000000000000000000ll);
vector<ll> d;
int main()
{
ios::sync_with_stdio(false); cin.tie(0);
cin>>n>>k;
for(int i = 1; i <= k; i++) cin>>x[i]>>y[i]>>xf[i]>>yf[i];
for(int i = 1; i <= k; i++) x[i] --, y[i] --, xf[i] --, yf[i] --;
for(int i = 1; i <= sqrt(n); i++)
{
if((n % i) != 0) continue;
d.push_back(i);
if(i != n/i) d.push_back(n/i);
}
for(auto r: d)
{
ll pretocerto = 0, pretoerrado = 0, tot;
if(r == n) continue;
tot = ( ((n/r) * (n/r)) + 1LL)/2LL;
tot = (tot * r * r);
//if(r != 2) continue;
for(int i = 1; i <= k; i++)
{
int linha = (x[i] % (2*r) < r ? 1 : 0), coluna = (y[i] % (2*r) < r ? 1 : 0);
if(!linha) coluna = !coluna;
if(!coluna) pretoerrado ++;
else pretocerto ++;
}
//cout<<custo<<" "<<branco<<"\n";
ans = min(ans, tot - pretocerto + pretoerrado);
tot = ( ((n/r) * (n/r)))/2LL;
tot = (tot * r * r);
ans = min(ans, tot + pretocerto - pretoerrado);
}
cout<<ans<<"\n";
}
# | 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... |