답안 #137918

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
137918 2019-07-28T14:06:15 Z vardan__02 Chessboard (IZhO18_chessboard) C++14
16 / 100
43 ms 4600 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,qanak[105],v,x[100005],y[100005],p1,p2,q1,q2,ans1,ans2;
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;
    if(color[n]==0)
    {
        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++;
        }
        p=n*n/2+1-u+v;
        ans=n*n/2-v+u;
        cout<<min(ans,p)<<endl;
        return 0;
    }
    for(i=n;i>=2;i--)
    {
        if(!color[i] && n%i==0)
        {
            p2=i;
            break;
        }
    }
    for(i=2;i<=n;i++)
    {
        if(!color[i] && n%i==0)
        {
            p1=i;
            break;
        }
    }
    for(i=1;i<=k;i++)
    cin>>x[i]>>y[i]>>x[i]>>y[i];
    for(i=1;i<=k;i++)
    {
        ll g,h;
        if(x[i]%p1==0)
            g=x[i]/p1;
        else
            g=x[i]/p1+1;
        if(y[i]%p1==0)
            h=y[i]/p1;
        else
            h=y[i]/p1+1;
        if(h%2==g%2)
            u++;
        else
            v++;
    }
    q1=n/p1;
    if(q1%2==1)
    ans1=p1*p1/2+1;
    else
    ans1=p1*p1/2;
    ans1=ans1*q1*q1;
    ans1=ans1-u+v;
    ans2=p1*p1/2;
    ans2=ans2*q1*q1;
    ans2=ans2-v+u;
    ans=min(ans1,ans2);
    u=0; v=0;
    for(i=1;i<=k;i++)
    {
        ll g,h;
        if(x[i]%p2==0)
            g=x[i]/p2;
        else
            g=x[i]/p2+1;
        if(y[i]%p2==0)
            h=y[i]/p2;
        else
            h=y[i]/p2+1;
        if(h%2==g%2)
            u++;
        else
            v++;
    }
    q2=n/p2;
    if(q2%2==1)
    ans1=p2*p2/2+1;
    else
    ans1=p2*p2/2;
    ans1=ans1*q2*q2;
    ans1=ans1-u+v;
    ans2=p2*p2/2;
    ans2=ans2*q2*q2;
    ans2=ans2-v+u;
    ans=min(ans,ans1);
    ans=min(ans,ans2);
    cout<<ans<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 4 ms 1144 KB Output is correct
6 Correct 4 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 3576 KB Output is correct
2 Correct 12 ms 1656 KB Output is correct
3 Correct 22 ms 2716 KB Output is correct
4 Correct 23 ms 2740 KB Output is correct
5 Correct 30 ms 3320 KB Output is correct
6 Correct 19 ms 2424 KB Output is correct
7 Correct 7 ms 1400 KB Output is correct
8 Correct 19 ms 2424 KB Output is correct
9 Correct 43 ms 4600 KB Output is correct
10 Correct 26 ms 3104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 3576 KB Output is correct
2 Correct 12 ms 1656 KB Output is correct
3 Correct 22 ms 2716 KB Output is correct
4 Correct 23 ms 2740 KB Output is correct
5 Correct 30 ms 3320 KB Output is correct
6 Correct 19 ms 2424 KB Output is correct
7 Correct 7 ms 1400 KB Output is correct
8 Correct 19 ms 2424 KB Output is correct
9 Correct 43 ms 4600 KB Output is correct
10 Correct 26 ms 3104 KB Output is correct
11 Incorrect 3 ms 1144 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1144 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
3 Correct 3 ms 1144 KB Output is correct
4 Correct 3 ms 1144 KB Output is correct
5 Correct 4 ms 1144 KB Output is correct
6 Correct 4 ms 1144 KB Output is correct
7 Correct 3 ms 1144 KB Output is correct
8 Correct 3 ms 1148 KB Output is correct
9 Correct 31 ms 3576 KB Output is correct
10 Correct 12 ms 1656 KB Output is correct
11 Correct 22 ms 2716 KB Output is correct
12 Correct 23 ms 2740 KB Output is correct
13 Correct 30 ms 3320 KB Output is correct
14 Correct 19 ms 2424 KB Output is correct
15 Correct 7 ms 1400 KB Output is correct
16 Correct 19 ms 2424 KB Output is correct
17 Correct 43 ms 4600 KB Output is correct
18 Correct 26 ms 3104 KB Output is correct
19 Incorrect 3 ms 1144 KB Output isn't correct
20 Halted 0 ms 0 KB -