Submission #137975

# Submission time Handle Problem Language Result Execution time Memory
137975 2019-07-28T17:05:42 Z vardan__02 Chessboard (IZhO18_chessboard) C++14
16 / 100
46 ms 2552 KB
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
ll n,k,p,u,ans,color[100005],i,j,v,x[100005],y[100005],p1,p2,q1,q2,ans1,ans2,t,q;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    for(i=2;i<=100000;i++)
    {
        if(!color[i])
        {
            for(j=2*i;j<=100000;j+=i)
                color[j]=1;
        }
    }
    cin>>n>>k;
    for(i=1;i<=k;i++)
    {
        cin>>x[i]>>y[i]>>x[i]>>y[i];
        if(x[i]%2==y[i]%2)
            u++;
        else
            v++;
    }
    if(n%2==0)
        p=n*n/2;
    else
        p=n*n/2+1;
    q=n*n/2;
    ans=min(p-u+v,q-v+u);
    for(j=2;j<=n;j++)
    {
        if(color[j]==0 && n%j==0)
        {
            u=0;
            v=0;
            t=n/j;
            for(i=1;i<=k;i++)
            {
                ll g,h;
                if(x[i]%t==0)
                    g=x[i]/t;
                else
                    g=x[i]/t+1;
                if(y[i]%t==0)
                    h=y[i]/t;
                else
                    h=y[i]/t+1;
                if(h%2==g%2)
                    u++;
                else
                    v++;
            }
            q=n/j;
            ans1=j*j/2+1;
            ans1=ans1*q*q;
            ans1=ans1-u+v;
            ans2=j*j/2;
            ans2=ans2*q*q;
            ans2=ans2-v+u;
            ans=min(ans,ans2);
            ans=min(ans,ans1);
        }
    }
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1144 KB Output is correct
2 Correct 4 ms 1144 KB Output is correct
3 Correct 4 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 2040 KB Output is correct
2 Correct 12 ms 1400 KB Output is correct
3 Correct 22 ms 1784 KB Output is correct
4 Correct 25 ms 1880 KB Output is correct
5 Correct 29 ms 1912 KB Output is correct
6 Correct 20 ms 1632 KB Output is correct
7 Correct 7 ms 1272 KB Output is correct
8 Correct 20 ms 1784 KB Output is correct
9 Correct 46 ms 2552 KB Output is correct
10 Correct 28 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1144 KB Output is correct
2 Correct 4 ms 1144 KB Output is correct
3 Correct 4 ms 1164 KB Output is correct
4 Correct 4 ms 1144 KB Output is correct
5 Correct 4 ms 1144 KB Output is correct
6 Incorrect 4 ms 1144 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1144 KB Output is correct
2 Correct 4 ms 1144 KB Output is correct
3 Correct 4 ms 1164 KB Output is correct
4 Correct 4 ms 1144 KB Output is correct
5 Correct 4 ms 1144 KB Output is correct
6 Incorrect 4 ms 1144 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 2040 KB Output is correct
2 Correct 12 ms 1400 KB Output is correct
3 Correct 22 ms 1784 KB Output is correct
4 Correct 25 ms 1880 KB Output is correct
5 Correct 29 ms 1912 KB Output is correct
6 Correct 20 ms 1632 KB Output is correct
7 Correct 7 ms 1272 KB Output is correct
8 Correct 20 ms 1784 KB Output is correct
9 Correct 46 ms 2552 KB Output is correct
10 Correct 28 ms 1912 KB Output is correct
11 Correct 4 ms 1144 KB Output is correct
12 Correct 4 ms 1144 KB Output is correct
13 Correct 4 ms 1164 KB Output is correct
14 Correct 4 ms 1144 KB Output is correct
15 Correct 4 ms 1144 KB Output is correct
16 Incorrect 4 ms 1144 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1144 KB Output is correct
2 Correct 4 ms 1144 KB Output is correct
3 Correct 4 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 3 ms 1144 KB Output is correct
6 Correct 3 ms 1016 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1144 KB Output is correct
9 Correct 33 ms 2040 KB Output is correct
10 Correct 12 ms 1400 KB Output is correct
11 Correct 22 ms 1784 KB Output is correct
12 Correct 25 ms 1880 KB Output is correct
13 Correct 29 ms 1912 KB Output is correct
14 Correct 20 ms 1632 KB Output is correct
15 Correct 7 ms 1272 KB Output is correct
16 Correct 20 ms 1784 KB Output is correct
17 Correct 46 ms 2552 KB Output is correct
18 Correct 28 ms 1912 KB Output is correct
19 Correct 4 ms 1144 KB Output is correct
20 Correct 4 ms 1144 KB Output is correct
21 Correct 4 ms 1164 KB Output is correct
22 Correct 4 ms 1144 KB Output is correct
23 Correct 4 ms 1144 KB Output is correct
24 Incorrect 4 ms 1144 KB Output isn't correct
25 Halted 0 ms 0 KB -