Submission #48832

# Submission time Handle Problem Language Result Execution time Memory
48832 2018-05-19T08:53:57 Z mrtsima22 Chessboard (IZhO18_chessboard) C++17
8 / 100
33 ms 2532 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;
ansT=ansS=0LL;
for(long long i=1LL;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];
a[i]--,b[i]--,c[i]--,d[i]--;	
}
ans=lmax;
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])
	{
		long long q1=(a[i])/p;
		long long q2=(b[i])/p;
		long long q=q1+q2;
		if(!(q)&1)
		{
			ansT++;
		}
		else
		{
			ansS++;
		}
	}	
}
long long O=ansT-ansS;
//---------------
long long o=n/v[j];
//--------------
if(O+o*o/2*v[j]*v[j]<ans)
ans=O+o*o/2*v[j]*v[j];
O=ansS-ansT;
if(O+(o*o+1)/2*v[j]*v[j]<ans)
ans=O+(o*o+1)/2*v[j]*v[j];
}
//cout<<ansT+K-ansS<<" "<<ansS+k-ansT<<endl;

cout<<ans<<endl;
}
/*

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



*/


Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:29: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 252 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 672 KB Output is correct
7 Correct 2 ms 676 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 2532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 2532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 432 KB Output is correct
4 Correct 2 ms 636 KB Output is correct
5 Correct 2 ms 636 KB Output is correct
6 Correct 2 ms 672 KB Output is correct
7 Correct 2 ms 676 KB Output is correct
8 Correct 2 ms 676 KB Output is correct
9 Incorrect 33 ms 2532 KB Output isn't correct
10 Halted 0 ms 0 KB -