#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
716 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
0 ms |
716 KB |
Output is correct |
3 |
Correct |
1 ms |
844 KB |
Output is correct |
4 |
Correct |
1 ms |
972 KB |
Output is correct |
5 |
Correct |
1 ms |
972 KB |
Output is correct |
6 |
Correct |
1 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
972 KB |
Output is correct |
8 |
Correct |
1 ms |
844 KB |
Output is correct |
9 |
Correct |
1 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
844 KB |
Output is correct |
11 |
Correct |
1 ms |
844 KB |
Output is correct |
12 |
Correct |
1 ms |
716 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
972 KB |
Output is correct |
15 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
0 ms |
716 KB |
Output is correct |
3 |
Correct |
1 ms |
844 KB |
Output is correct |
4 |
Correct |
1 ms |
972 KB |
Output is correct |
5 |
Correct |
1 ms |
972 KB |
Output is correct |
6 |
Correct |
1 ms |
972 KB |
Output is correct |
7 |
Correct |
1 ms |
972 KB |
Output is correct |
8 |
Correct |
1 ms |
844 KB |
Output is correct |
9 |
Correct |
1 ms |
1100 KB |
Output is correct |
10 |
Correct |
1 ms |
844 KB |
Output is correct |
11 |
Correct |
1 ms |
844 KB |
Output is correct |
12 |
Correct |
1 ms |
716 KB |
Output is correct |
13 |
Correct |
1 ms |
844 KB |
Output is correct |
14 |
Correct |
1 ms |
972 KB |
Output is correct |
15 |
Correct |
1 ms |
716 KB |
Output is correct |
16 |
Correct |
20 ms |
11488 KB |
Output is correct |
17 |
Correct |
37 ms |
12048 KB |
Output is correct |
18 |
Correct |
37 ms |
12040 KB |
Output is correct |
19 |
Correct |
37 ms |
11644 KB |
Output is correct |
20 |
Correct |
38 ms |
11596 KB |
Output is correct |
21 |
Correct |
37 ms |
11992 KB |
Output is correct |
22 |
Correct |
16 ms |
9548 KB |
Output is correct |
23 |
Correct |
26 ms |
11724 KB |
Output is correct |
24 |
Correct |
37 ms |
12040 KB |
Output is correct |
25 |
Correct |
17 ms |
11724 KB |
Output is correct |
26 |
Correct |
27 ms |
11504 KB |
Output is correct |
27 |
Correct |
33 ms |
11664 KB |
Output is correct |
28 |
Correct |
36 ms |
11524 KB |
Output is correct |
29 |
Correct |
22 ms |
11724 KB |
Output is correct |
30 |
Correct |
16 ms |
11604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
716 KB |
Output is correct |
3 |
Correct |
1 ms |
716 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
1 ms |
716 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
1 ms |
716 KB |
Output is correct |
8 |
Correct |
1 ms |
716 KB |
Output is correct |
9 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |