#include <random>
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#define fr first
#define sc second
#define ad push_back
using namespace std;
using ll = long long;
mt19937 rnd(348502);
const int N = 100005;
pair<int, int> ans[N];
void solve()
{
int n, i, j, x, y, x1, y1, k;
cin >> n >> k;
vector<int> baj;
baj.push_back(1);
for ( i = 2; i * i < n; i++)
{
if (n % i == 0)
{
baj.push_back(i);
baj.push_back(n / i);
}
}
if (i * i == n)
baj.push_back(i);
for ( i = 0; i < k; i++)
{
cin >> x >> y >> x1 >> y1;
if (x != x1 || y != y1)
{
while (1)
{
x = x;
}
}
for ( j = 0; j < baj.size(); j++)
{
if (((x - 1) / baj[j] + (y - 1) / baj[j]) % 2 == 1)
{
ans[j].first--;
ans[j].second++;
}
else
{
ans[j].first++;
ans[j].second--;
}
}
}
ll anss = 1e18;
for ( i = 0; i < baj.size(); i++)
{
anss = min(anss, ll(n) * n / 2 + min(ans[i].first, ans[i].second));
}
cout << anss;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
solve();
}
return 0;
}
Compilation message
chessboard.cpp: In function 'void solve()':
chessboard.cpp:58:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for ( j = 0; j < baj.size(); j++)
| ~~^~~~~~~~~~~~
chessboard.cpp:73:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | for ( i = 0; i < baj.size(); i++)
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |