제출 #895295

#제출 시각아이디문제언어결과실행 시간메모리
895295AndreyChessboard (IZhO18_chessboard)C++14
100 / 100
557 ms6320 KiB
#include<bits/stdc++.h> using namespace std; long long calc(long long x1, long long x2, long long y1, long long y2, long long k) { long long br1 = (x2/(2*k))*k+min(k-1,x2%(2*k))+1; if(x1 > 0) { x1--; br1-=(x1/(2*k))*k+min(k-1,x1%(2*k))+1; } else { x1--; } long long br2 = (y2/(2*k))*k+min(k-1,y2%(2*k))+1; if(y1 > 0) { y1--; br2-=(y1/(2*k))*k+min(k-1,y1%(2*k))+1; } else { y1--; } return br1*br2+(x2-x1-br1)*(y2-y1-br2); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n,k,x1,y1,x2,y2,ans = LLONG_MAX; cin >> n >> k; vector<pair<long long,long long>> haha(0); vector<pair<long long,long long>> bruh(0); for(long long i = 0; i < k; i++) { cin >> x1 >> y1 >> x2 >> y2; haha.push_back({x1-1,y1-1}); bruh.push_back({x2-1,y2-1}); } for(long long i = 1; i < n; i++) { if(n%i == 0) { long long br = (((n/i)*(n/i)+1)/2)*i*i; for(long long j = 0; j < k; j++) { long long c = (bruh[j].second-haha[j].second+1)*(bruh[j].first-haha[j].first+1)-2*calc(haha[j].first,bruh[j].first,haha[j].second,bruh[j].second,i); br+=c; } ans = min(ans,br); br = (((n/i)*(n/i))/2)*i*i; for(long long j = 0; j < k; j++) { long long c = (bruh[j].second-haha[j].second+1)*(bruh[j].first-haha[j].first+1)-2*calc(haha[j].first,bruh[j].first,haha[j].second,bruh[j].second,i); br-=c; } ans = min(ans,br); } } cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...