/** kutbilim.one **/
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define int long long
#define endl '\n'
ifstream in("test.txt");
#define cin in
const signed MAX = 1001;
vector< vector<signed> > a(MAX, vector<signed> (MAX, 0));
int n, k;
bool isprime(int n){
if(n == 2) return true;
for(int i = 2; i*i <= n; i++)
if(n%i == 0) return false;
return true;
}
void solve_1(){
int result = INT_MAX;
for(int i = 1; i < n; i++){
if(n%i) continue;
result = min(result, ((n*n)/(i*i)/2)*(i*i));
}
cout << result;
}
void solve_2(){
int cnt[2] = {0, 0};
for(int i = 1; i <= k; i++){
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
for(int x = x1; x <= x2; x++)
for(int y = y1; y <= y2; y++){
a[x][y] = 1;
cnt[(x+y)%2]++;
}
}
cout << min(n*n/2-cnt[1] + cnt[0], n*n/2+1-cnt[0] + cnt[1]);
}
void solve_3_4(){
vector<pair<int, int>> sides(n, {0, 0});
vector<int> f;
for(int i = 1; i*i <= n; i++){
if(n % i == 0){
f.push_back(i);
if(i != 1) f.push_back(n/i);
}
}
for(int i = 1; i <= k; i++){
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
for(int x = x1; x <= x2; x++)
for(int y = y1; y <= y2; y++){
a[x][y] = 1;
for(auto d : f){
if(((x+y+d-1)/d) % 2) sides[d].first++;
else sides[d].second++;
}
}
}
int result = LONG_MAX;
for(auto d : f){
result = min(
result,
((n*n)/(d*d)/2)*(d*d) - sides[d].second + sides[d].first
);
if((n*n)/(d*d) % 2 == 1)
result = min(
result,
((n*n)/(d*d)/2)*(d*d)+(d*d) - sides[d].first + sides[d].second
);
}
cout << result;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> k;
if(k == 0){
solve_1();
}else if(isprime(n)){
solve_2();
}else{
solve_3_4();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
4332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
4332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |