제출 #48840

#제출 시각아이디문제언어결과실행 시간메모리
48840mrtsima22Chessboard (IZhO18_chessboard)C++17
39 / 100
62 ms2260 KiB
#include <bits/stdc++.h>
using namespace std;
#define lo long
const int lmax=1999999999;
const long long lmx=1999999999999999999;
int n,k;
long long ans=lmx,ansT;
int a[100003],b[100003],c[100003],d[100004];
int main(){std::ios::sync_with_stdio(false);
cin>>n>>k;
ansT=0LL;
for(long long i=0;i<k;i++)
{
	cin>>a[i]>>b[i]>>c[i]>>d[i];
a[i]--,b[i]--,c[i]--,d[i]--;	
}
ans=lmax;
  for(int j = 1; j < n; ++j)
    if(n % j == 0) { 
      ansT = 0;
      for(int i = 0; i < k; ++i)
        if((a[i]/j + b[i]/j) % 2 == 0)
          ++ansT;
      ansT = ansT * 2 - k;
      if(ansT + (long long)n * n / j / j / 2 * j * j < ans)
        ans = ansT + (long long)n * n / j / j / 2 * j * j;
      ansT = -ansT;
      if(ansT + ((long long)n * n / j / j + 1) / 2 * j * j < ans)
        ans = ansT + ((long long)n * n / j / j + 1) / 2 * j * j;
    }
//cout<<ansT+K-ansS<<" "<<ansS+k-ansT<<endl;

cout<<ans<<endl;
}
/*

                   *         *
                  * *       * *
                 *   *     *   *
                *     *   *     *
               *       * *       *
               *        *        *
                *               *
                 *             *
                  *           *
                   *         *
                    *       *
                     *     *
                      *   *
                       * *
                        *



*/


#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...