Submission #48830

# Submission time Handle Problem Language Result Execution time Memory
48830 2018-05-19T08:23:08 Z mrtsima22 Chessboard (IZhO18_chessboard) C++17
16 / 100
47 ms 3448 KB
#include <bits/stdc++.h>
using namespace std;
#define lo long
const int lmax=1999999999;
const long long lmx=1999999999999999999;
long long n;
long long k;
long long ans=lmax,ansT,ansS;
long long a[100003],b[100003],c[100003],d[100004];
vector<long long>v;
long long k1;
int main(){std::ios::sync_with_stdio(false);
cin>>n>>k;
if(k==0LL){
ans=n*n/2;
for(long long j=2;j<=n/2+1;j++)
{
	if(n%j==0)
	{
		long long k=n/j;
		k=k*k;
		ans=min(ans,j*j/2*k);
	}
}
cout<<ans<<endl;
return 0;
}
ansT=ansS=0LL;
for(long long i=2LL;i<n;i++)
{
	if(n%i==0)
	{
		v.push_back(i);
	}
}
	ansT=ansS=0;
for(long long i=0;i<k;i++)
{
	cin>>a[i]>>b[i]>>c[i]>>d[i];
	if(a[i]==c[i]&&b[i]==d[i])
	{
		if((a[i]+b[i])&1)
		{
			ansT++;
		}
		else
		{
			ansS++;
		}
	}	
}
k1=n*n/2;
long long K=k1;
if(n&1)K++;
ans=min(ansT+K-ansS,ansS+k1-ansT);
for(int j=0;j<v.size();j++){
long long p=v[j];
ansS=ansT=0;
for(int i=0;i<k;i++)
{
	if(a[i]==c[i]&&b[i]==d[i])
	{
		long long q1=(a[i]-1)/p+1;
		long long q2=(b[i]-1)/p+1;
		long long q=q1+q2;
		if((q)&1)
		{
			ansT++;
		}
		else
		{
			ansS++;
		}
	}	
}
long long O=n/v[j];
//---------------

//--------------
k1=v[j]*v[j]/2*O*O;
K=n*n-k1;
ans=min(ansS+k1-ansT,ansT+K-ansS);
}
//cout<<ansT+K-ansS<<" "<<ansS+k-ansT<<endl;

cout<<ans<<endl;
}
/*

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



*/


Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:56:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 for(int j=0;j<v.size();j++){
             ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 288 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 2 ms 712 KB Output is correct
8 Correct 2 ms 712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 2544 KB Output is correct
2 Correct 12 ms 2544 KB Output is correct
3 Correct 22 ms 2544 KB Output is correct
4 Correct 24 ms 2544 KB Output is correct
5 Correct 33 ms 2544 KB Output is correct
6 Correct 21 ms 2544 KB Output is correct
7 Correct 6 ms 2544 KB Output is correct
8 Correct 21 ms 2544 KB Output is correct
9 Correct 46 ms 3448 KB Output is correct
10 Correct 29 ms 3448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3448 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 47 ms 2544 KB Output is correct
2 Correct 12 ms 2544 KB Output is correct
3 Correct 22 ms 2544 KB Output is correct
4 Correct 24 ms 2544 KB Output is correct
5 Correct 33 ms 2544 KB Output is correct
6 Correct 21 ms 2544 KB Output is correct
7 Correct 6 ms 2544 KB Output is correct
8 Correct 21 ms 2544 KB Output is correct
9 Correct 46 ms 3448 KB Output is correct
10 Correct 29 ms 3448 KB Output is correct
11 Incorrect 2 ms 3448 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 288 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 584 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 2 ms 712 KB Output is correct
8 Correct 2 ms 712 KB Output is correct
9 Correct 47 ms 2544 KB Output is correct
10 Correct 12 ms 2544 KB Output is correct
11 Correct 22 ms 2544 KB Output is correct
12 Correct 24 ms 2544 KB Output is correct
13 Correct 33 ms 2544 KB Output is correct
14 Correct 21 ms 2544 KB Output is correct
15 Correct 6 ms 2544 KB Output is correct
16 Correct 21 ms 2544 KB Output is correct
17 Correct 46 ms 3448 KB Output is correct
18 Correct 29 ms 3448 KB Output is correct
19 Incorrect 2 ms 3448 KB Output isn't correct
20 Halted 0 ms 0 KB -