답안 #89451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
89451 2018-12-14T17:34:08 Z Harvey_Rollens Chessboard (IZhO18_chessboard) C++17
70 / 100
555 ms 5464 KB
#include<bits/stdc++.h>
#define ll long long
#define st string
#define fr first
#define se second

const long long mod=1e9+7;

using namespace std;

vector<pair<ll, ll> > v;
ll a[100100], b[100100], k, ans=10000001000000, a1[100100], b1[100100];

void f(ll x)
{
    for(ll i=1; i*i<=x; i++)
    {
        if(x%i==0)
        {
            v.push_back({i, x/i});
            if(i>1 && i!=x/i) v.push_back({x/i, i});
        }
    }
}

void pro(ll p, ll o)
{
    ll kb1=0, kb2=0;
    for(ll i=1; i<=k; i++)
    {
        ll x=a[i], y=b[i];

        x=(x+p-1)/p;
        y=(y+p-1)/p;

        if((x%2!=0 && y%2!=0) || (x%2==0 && y%2==0))
        {
            kb1++;
        }
        else kb2++;
    }

    //cout<<"kb1="<<kb1<<" kb2="<<kb2<<endl;

    kb2=kb2+((o*o)/2+(o*o)%2)*p*p-(k-kb2);
    kb1=kb1+((o*o)/2)*p*p-(k-kb1);

    //cout<<"PPP= "<<kb1<<" "<<kb2<<" "<<p<<" "<<o<<'\n';

    ans=min(kb1, min(ans, kb2));
}

main()
{
    //freopen("1.txt", "r", stdin);
    //freopen("1.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n;
    cin>>n>>k;

    f(n);

    for(ll i=1; i<=k; i++)
        cin>>a[i]>>b[i]>>a1[i]>>b1[i];

    //cout<<v.size()<<endl;

    if(v.size()==1)
    {
        ll kch=0, kb=0, s=0;
        for(ll i=1; i<=k; i++)
        {
            ll x=a[i], y=b[i], x1=a1[i], y1=b1[i];
            ll l=(x1-x)+1, r=(y1-y)+1;

            if((x%2==0 && y%2==0) || (x%2!=0 && y%2!=0))
            {
                kb+=(l*r)/2+(l*r)%2;
                kch+=(l*r)/2;
            }
            else
            {
                kb+=(l*r)/2;
                kch+=(l*r)/2+(l*r)%2;
            }

            s+=(l*r);
        }
        //cout<<kb<<" "<<kch<<endl;

        kch=kch+(n*n)/2+(n*n)%2-(s-kch);
        kb=kb+(n*n)/2-(s-kb);

        //cout<<kb<<" "<<kch<<" ";
        cout<<min(kb, kch);
        return 0;
    }
    //cout<<"ANS"<<endl;

    for(ll i=0; i<v.size(); i++)
    {
        //cout<<v[i].fr<<" "<<v[i].se<<endl;
        pro(v[i].fr, v[i].se);
    }

    cout<<ans;
    return 0;
}
/*
3 5
1 1 1 1
1 3 1 3
2 2 2 2
3 1 3 1
3 3 3 3
*/

Compilation message

chessboard.cpp:53:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
chessboard.cpp: In function 'int main()':
chessboard.cpp:103:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(ll i=0; i<v.size(); i++)
                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 448 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 544 KB Output is correct
5 Correct 2 ms 544 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 2452 KB Output is correct
2 Correct 9 ms 2452 KB Output is correct
3 Correct 18 ms 2452 KB Output is correct
4 Correct 20 ms 2452 KB Output is correct
5 Correct 26 ms 2452 KB Output is correct
6 Correct 17 ms 2452 KB Output is correct
7 Correct 5 ms 2452 KB Output is correct
8 Correct 30 ms 2452 KB Output is correct
9 Correct 42 ms 3424 KB Output is correct
10 Correct 23 ms 3424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3424 KB Output is correct
2 Correct 2 ms 3424 KB Output is correct
3 Correct 2 ms 3424 KB Output is correct
4 Correct 2 ms 3424 KB Output is correct
5 Correct 3 ms 3424 KB Output is correct
6 Correct 2 ms 3424 KB Output is correct
7 Correct 1 ms 3424 KB Output is correct
8 Correct 3 ms 3424 KB Output is correct
9 Correct 2 ms 3424 KB Output is correct
10 Correct 2 ms 3424 KB Output is correct
11 Correct 2 ms 3424 KB Output is correct
12 Correct 2 ms 3424 KB Output is correct
13 Correct 2 ms 3424 KB Output is correct
14 Correct 3 ms 3424 KB Output is correct
15 Correct 3 ms 3424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3424 KB Output is correct
2 Correct 2 ms 3424 KB Output is correct
3 Correct 2 ms 3424 KB Output is correct
4 Correct 2 ms 3424 KB Output is correct
5 Correct 3 ms 3424 KB Output is correct
6 Correct 2 ms 3424 KB Output is correct
7 Correct 1 ms 3424 KB Output is correct
8 Correct 3 ms 3424 KB Output is correct
9 Correct 2 ms 3424 KB Output is correct
10 Correct 2 ms 3424 KB Output is correct
11 Correct 2 ms 3424 KB Output is correct
12 Correct 2 ms 3424 KB Output is correct
13 Correct 2 ms 3424 KB Output is correct
14 Correct 3 ms 3424 KB Output is correct
15 Correct 3 ms 3424 KB Output is correct
16 Correct 14 ms 3424 KB Output is correct
17 Correct 33 ms 3424 KB Output is correct
18 Correct 50 ms 3708 KB Output is correct
19 Correct 126 ms 3708 KB Output is correct
20 Correct 144 ms 3836 KB Output is correct
21 Correct 30 ms 3836 KB Output is correct
22 Correct 2 ms 3836 KB Output is correct
23 Correct 27 ms 3836 KB Output is correct
24 Correct 43 ms 3836 KB Output is correct
25 Correct 8 ms 3836 KB Output is correct
26 Correct 27 ms 3836 KB Output is correct
27 Correct 40 ms 3836 KB Output is correct
28 Correct 47 ms 3836 KB Output is correct
29 Correct 14 ms 3836 KB Output is correct
30 Correct 3 ms 3836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 2452 KB Output is correct
2 Correct 9 ms 2452 KB Output is correct
3 Correct 18 ms 2452 KB Output is correct
4 Correct 20 ms 2452 KB Output is correct
5 Correct 26 ms 2452 KB Output is correct
6 Correct 17 ms 2452 KB Output is correct
7 Correct 5 ms 2452 KB Output is correct
8 Correct 30 ms 2452 KB Output is correct
9 Correct 42 ms 3424 KB Output is correct
10 Correct 23 ms 3424 KB Output is correct
11 Correct 2 ms 3424 KB Output is correct
12 Correct 2 ms 3424 KB Output is correct
13 Correct 2 ms 3424 KB Output is correct
14 Correct 2 ms 3424 KB Output is correct
15 Correct 3 ms 3424 KB Output is correct
16 Correct 2 ms 3424 KB Output is correct
17 Correct 1 ms 3424 KB Output is correct
18 Correct 3 ms 3424 KB Output is correct
19 Correct 2 ms 3424 KB Output is correct
20 Correct 2 ms 3424 KB Output is correct
21 Correct 2 ms 3424 KB Output is correct
22 Correct 2 ms 3424 KB Output is correct
23 Correct 2 ms 3424 KB Output is correct
24 Correct 3 ms 3424 KB Output is correct
25 Correct 3 ms 3424 KB Output is correct
26 Correct 14 ms 3424 KB Output is correct
27 Correct 33 ms 3424 KB Output is correct
28 Correct 50 ms 3708 KB Output is correct
29 Correct 126 ms 3708 KB Output is correct
30 Correct 144 ms 3836 KB Output is correct
31 Correct 30 ms 3836 KB Output is correct
32 Correct 2 ms 3836 KB Output is correct
33 Correct 27 ms 3836 KB Output is correct
34 Correct 43 ms 3836 KB Output is correct
35 Correct 8 ms 3836 KB Output is correct
36 Correct 27 ms 3836 KB Output is correct
37 Correct 40 ms 3836 KB Output is correct
38 Correct 47 ms 3836 KB Output is correct
39 Correct 14 ms 3836 KB Output is correct
40 Correct 3 ms 3836 KB Output is correct
41 Correct 112 ms 3836 KB Output is correct
42 Correct 51 ms 3836 KB Output is correct
43 Correct 74 ms 3836 KB Output is correct
44 Correct 49 ms 3836 KB Output is correct
45 Correct 42 ms 3836 KB Output is correct
46 Correct 123 ms 3836 KB Output is correct
47 Correct 39 ms 4092 KB Output is correct
48 Correct 62 ms 5176 KB Output is correct
49 Correct 49 ms 5176 KB Output is correct
50 Correct 504 ms 5260 KB Output is correct
51 Correct 544 ms 5464 KB Output is correct
52 Correct 489 ms 5464 KB Output is correct
53 Correct 541 ms 5464 KB Output is correct
54 Correct 502 ms 5464 KB Output is correct
55 Correct 555 ms 5464 KB Output is correct
56 Correct 486 ms 5464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 448 KB Output is correct
3 Correct 2 ms 448 KB Output is correct
4 Correct 2 ms 544 KB Output is correct
5 Correct 2 ms 544 KB Output is correct
6 Correct 2 ms 544 KB Output is correct
7 Correct 2 ms 544 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
9 Correct 28 ms 2452 KB Output is correct
10 Correct 9 ms 2452 KB Output is correct
11 Correct 18 ms 2452 KB Output is correct
12 Correct 20 ms 2452 KB Output is correct
13 Correct 26 ms 2452 KB Output is correct
14 Correct 17 ms 2452 KB Output is correct
15 Correct 5 ms 2452 KB Output is correct
16 Correct 30 ms 2452 KB Output is correct
17 Correct 42 ms 3424 KB Output is correct
18 Correct 23 ms 3424 KB Output is correct
19 Correct 2 ms 3424 KB Output is correct
20 Correct 2 ms 3424 KB Output is correct
21 Correct 2 ms 3424 KB Output is correct
22 Correct 2 ms 3424 KB Output is correct
23 Correct 3 ms 3424 KB Output is correct
24 Correct 2 ms 3424 KB Output is correct
25 Correct 1 ms 3424 KB Output is correct
26 Correct 3 ms 3424 KB Output is correct
27 Correct 2 ms 3424 KB Output is correct
28 Correct 2 ms 3424 KB Output is correct
29 Correct 2 ms 3424 KB Output is correct
30 Correct 2 ms 3424 KB Output is correct
31 Correct 2 ms 3424 KB Output is correct
32 Correct 3 ms 3424 KB Output is correct
33 Correct 3 ms 3424 KB Output is correct
34 Correct 14 ms 3424 KB Output is correct
35 Correct 33 ms 3424 KB Output is correct
36 Correct 50 ms 3708 KB Output is correct
37 Correct 126 ms 3708 KB Output is correct
38 Correct 144 ms 3836 KB Output is correct
39 Correct 30 ms 3836 KB Output is correct
40 Correct 2 ms 3836 KB Output is correct
41 Correct 27 ms 3836 KB Output is correct
42 Correct 43 ms 3836 KB Output is correct
43 Correct 8 ms 3836 KB Output is correct
44 Correct 27 ms 3836 KB Output is correct
45 Correct 40 ms 3836 KB Output is correct
46 Correct 47 ms 3836 KB Output is correct
47 Correct 14 ms 3836 KB Output is correct
48 Correct 3 ms 3836 KB Output is correct
49 Correct 112 ms 3836 KB Output is correct
50 Correct 51 ms 3836 KB Output is correct
51 Correct 74 ms 3836 KB Output is correct
52 Correct 49 ms 3836 KB Output is correct
53 Correct 42 ms 3836 KB Output is correct
54 Correct 123 ms 3836 KB Output is correct
55 Correct 39 ms 4092 KB Output is correct
56 Correct 62 ms 5176 KB Output is correct
57 Correct 49 ms 5176 KB Output is correct
58 Correct 504 ms 5260 KB Output is correct
59 Correct 544 ms 5464 KB Output is correct
60 Correct 489 ms 5464 KB Output is correct
61 Correct 541 ms 5464 KB Output is correct
62 Correct 502 ms 5464 KB Output is correct
63 Correct 555 ms 5464 KB Output is correct
64 Correct 486 ms 5464 KB Output is correct
65 Correct 2 ms 5464 KB Output is correct
66 Incorrect 2 ms 5464 KB Output isn't correct
67 Halted 0 ms 0 KB -