# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
169433 | RafaelSus | Chessboard (IZhO18_chessboard) | C++14 | 279 ms | 7032 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
typedef long long ll;
const ll inf=1e18+18ll;
#define pb push_back
ll n,k;
ll a[N];
vector<int> J[N];
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n;
cin>>n>>k;
/*if(k==0){
cout<<(n*1ll*n/2ll)<<'\n';
return 0;
}*/
for(int i=0;i<k;i++){
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
J[y1].push_back(n-x1+1);
}
vector<int> div;div.push_back(1);
for(int i=2;i*i<=n;i++){
if(n%i==0){
div.push_back(i);
if(n/i!=i)div.push_back(n/i);
}
}
sort(div.begin(),div.end());
ll answ=n*1ll*n;
for(int i=0;i<div.size();i++){
ll tmp=0ll;
//cerr<<div[i]<<' ';
ll x=n/div[i];
if(x%2){ll y=x/2+1,z=x/2;tmp=y*y+z*z;}
else{ll y=x/2;tmp=y*y+y*y;}
tmp=tmp*1ll*div[i]*1ll*div[i];//cerr<<tmp<<' ';
for(int j=1;j<=n;j++){//cerr<<tmp<<' ';
for(int p=0;p<J[j].size();p++){
if(j%div[i]==0){
if((j/div[i])%2){
if(J[j][p]%div[i]==0){
if((J[j][p]/div[i])%2){
tmp--;
}else tmp++;
}else if((J[j][p]/div[i])%2==0){
tmp--;
}else tmp++;
}else{
if(J[j][p]%div[i]==0){
if((J[j][p]/div[i])%2==0){
tmp--;
}else tmp++;
}else if((J[j][p]/div[i])%2==1){
tmp--;
}else tmp++;
}
}else if((j/div[i])%2==0){
if(J[j][p]%div[i]==0){
if((J[j][p]/div[i])%2){
tmp--;
}else tmp++;
}else if((J[j][p]/div[i])%2==0){
tmp--;
}else tmp++;
}else if((j/div[i])%2==1){
if(J[j][p]%div[i]==0){
if((J[j][p]/div[i])%2==0){
tmp--;
}else tmp++;
}else if((J[j][p]/div[i])%2==1){
tmp--;
}else tmp++;
}
}//cerr<<tmp<<' ';
}
answ=min(answ,min(tmp,n*1ll*n-tmp));
//cerr<<answ<<'\n';
}
cout<<answ<<'\n';
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |