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 <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef int ll;
#define all(x) x.begin(),x.end()
#define al(a,n) (a,a+n)
#define se second
#define fr first
#define m_p make_pair
const ll N = 1005;
const ll mod = 1000 * 1000 * 1000 + 7;
const ll inf = 1000000009;
ll n, m, k, z, t, x, y, ans, pat,a[N][N];
pair<ll, ll> p[N][N];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < m; ++i)
{
cin >> x >> y >> x >> y;
a[x][y] = 1;
}
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= n; ++j)
{
if (a[i][j] == 1)
{
p[i][j].first = p[i][j - 1].first + p[i - 1][j].first - p[i - 1][j - 1].first+1;
p[i][j].second = p[i][j - 1].second + p[i - 1][j].second - p[i - 1][j - 1].second;
}
else
{
p[i][j].second = p[i][j - 1].second + p[i - 1][j].second - p[i - 1][j - 1].second + 1;
p[i][j].first = p[i][j - 1].first + p[i - 1][j].first - p[i - 1][j - 1].first;
}
}
}
ans = inf;
for (int ii = 1; ii < n; ++ii)
{
x = 0;
y = 0;
if (n % ii == 0)
{
for (int i = ii; i <= n; i += ii)
{
for (int j = ii; j <= n; j += ii)
{
if ((i / ii + j / ii) % 2 == 0)
{
x += p[i][j].second + p[i - ii][j - ii].second - p[i][j - ii].second - p[i - ii][j].second;
y += p[i][j].first + p[i - ii][j - ii].first - p[i][j - ii].first - p[i - ii][j].first;
}
else
{
x += p[i][j].first + p[i - ii][j - ii].first - p[i][j - ii].first - p[i - ii][j].first;
y += p[i][j].second + p[i - ii][j - ii].second - p[i][j - ii].second - p[i - ii][j].second;
}
}
}
ans = min(ans, min(x, y));
}
}
cout << ans << endl;
return 0;
}
# | 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... |