답안 #172818

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172818 2020-01-02T16:28:10 Z muhammad_hokimiyon Chessboard (IZhO18_chessboard) C++14
47 / 100
2000 ms 6224 KB
#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define ll long long

using namespace std;

const int N = 1e5 + 7;
const int M = 23;
const int mod = 998244353;

ll n,k;
ll A[N];
ll B[N];
ll C[N];
ll D[N];
ll x1, y2, a, b;

ll f( ll x , ll y , ll div )
{
    x1 = y / div;
    y2 = x / div;
    x1 = x1 * y2 + 1;
    x1 /= 2;
    x1 *= div * div;
    a = y % div;
    b = x % div;
    if( ((y - 1) / div % 2 == 0 && div > 1) ){
        x1 += ((x / div + 1) / 2) * div * a;
    }else{
        x1 += x / div / 2 * div * a;
    }
    if( ((x - 1) / div % 2 == 0) ){
        x1 += (y / div + 1) / 2 * div * b;
    }else{
        x1 += y / div / 2 * div * b;
    }
    if( ((x - 1) / div % 2 == 1 && (y - 1) / div % 2 == 1) || ((x - 1) / div % 2 == 0 && (y - 1) / div % 2 == 0) ){
        x1 += (x % div) * (y % div);
    }
    //cout << x << " " << y << " " << div << " " << x1 << " " << fg[x][y] << "\n";
    return x1;
}

void solve1()
{
    cin >> n >> k;
    vector < ll > div;
    for( int i = 1; i < n; i++ ){
        if( n % i == 0 )div.push_back(i);
    }
    for( int i = 0; i < k; i++ ){
        cin >> A[i] >> B[i] >> C[i] >> D[i];
    }
    ll ans = 1e14;
    for( int i = 0; i < (int)div.size(); i++ ){
        ll nn = n / div[i];
        ll fg = div[i] * div[i];
        ll B1 = (nn + 1) / 2;
        ll B2 = nn / 2;
        B1 *= fg;
        B2 *= fg;
        B1 *= (nn + 1) / 2;
        B2 *= nn / 2;
        B1 += B2;
        ll B3 = (nn) / 2;
        ll B4 = (nn + 1) / 2;
        B3 *= fg;
        B4 *= fg;
        B3 *= (nn + 1) / 2;
        B4 *= (nn) / 2;
        B3 += B4;
        vector < ll > w(k , 0);
        vector < ll > b(k , 0);
        ll x, y;
        for( int j = 0; j < k; j++ ){
            x = f(C[j] , D[j] , div[i]) - f(C[j] , B[j] - 1 , div[i]) -
            f(A[j] - 1, D[j] , div[i]) + f(A[j] - 1 , B[j] - 1 , div[i]);
            y = (C[j] - A[j] + 1) * (D[j] - B[j] + 1);
            w[j] = y - x;
            b[j] = x;
        }
        x = 0;
        y = 0;
        //cout << B1 << " " << B3 << "\n";
        for( int j = 0; j < k; j++ ){
            B1 -= b[j];
            x += w[j];
            y += b[j];
            B3 -= w[j];
            //if( div[i] == 1 )cout << b[j] << " ";
        }
        //cout << "\n";
        //cout << B1 + x << " " << B3 + y << " " << div[i] << "\n";
        ans = min(ans , B1 + x);
        ans = min(ans , B3 + y);
    }
    cout << ans;
}

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

    int cghf = 1;//cin >> cghf;
    while( cghf-- ){
        solve1();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 4220 KB Output is correct
2 Correct 13 ms 1528 KB Output is correct
3 Correct 30 ms 3064 KB Output is correct
4 Correct 33 ms 3448 KB Output is correct
5 Correct 40 ms 3704 KB Output is correct
6 Correct 26 ms 2812 KB Output is correct
7 Correct 7 ms 888 KB Output is correct
8 Correct 27 ms 2808 KB Output is correct
9 Correct 64 ms 5496 KB Output is correct
10 Correct 37 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 388 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 388 KB Output is correct
13 Correct 4 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 248 KB Output is correct
16 Correct 32 ms 2168 KB Output is correct
17 Correct 53 ms 4572 KB Output is correct
18 Correct 112 ms 5964 KB Output is correct
19 Correct 633 ms 5580 KB Output is correct
20 Correct 708 ms 6224 KB Output is correct
21 Correct 53 ms 5116 KB Output is correct
22 Correct 4 ms 376 KB Output is correct
23 Correct 92 ms 3088 KB Output is correct
24 Correct 101 ms 5496 KB Output is correct
25 Correct 20 ms 888 KB Output is correct
26 Correct 66 ms 3960 KB Output is correct
27 Correct 112 ms 4304 KB Output is correct
28 Correct 108 ms 5776 KB Output is correct
29 Correct 22 ms 2424 KB Output is correct
30 Correct 5 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 4220 KB Output is correct
2 Correct 13 ms 1528 KB Output is correct
3 Correct 30 ms 3064 KB Output is correct
4 Correct 33 ms 3448 KB Output is correct
5 Correct 40 ms 3704 KB Output is correct
6 Correct 26 ms 2812 KB Output is correct
7 Correct 7 ms 888 KB Output is correct
8 Correct 27 ms 2808 KB Output is correct
9 Correct 64 ms 5496 KB Output is correct
10 Correct 37 ms 3448 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 388 KB Output is correct
23 Correct 4 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 248 KB Output is correct
26 Correct 32 ms 2168 KB Output is correct
27 Correct 53 ms 4572 KB Output is correct
28 Correct 112 ms 5964 KB Output is correct
29 Correct 633 ms 5580 KB Output is correct
30 Correct 708 ms 6224 KB Output is correct
31 Correct 53 ms 5116 KB Output is correct
32 Correct 4 ms 376 KB Output is correct
33 Correct 92 ms 3088 KB Output is correct
34 Correct 101 ms 5496 KB Output is correct
35 Correct 20 ms 888 KB Output is correct
36 Correct 66 ms 3960 KB Output is correct
37 Correct 112 ms 4304 KB Output is correct
38 Correct 108 ms 5776 KB Output is correct
39 Correct 22 ms 2424 KB Output is correct
40 Correct 5 ms 508 KB Output is correct
41 Correct 514 ms 5332 KB Output is correct
42 Correct 113 ms 5700 KB Output is correct
43 Correct 266 ms 5332 KB Output is correct
44 Correct 111 ms 5496 KB Output is correct
45 Correct 69 ms 5904 KB Output is correct
46 Correct 575 ms 5688 KB Output is correct
47 Correct 61 ms 5244 KB Output is correct
48 Correct 193 ms 5376 KB Output is correct
49 Correct 102 ms 5240 KB Output is correct
50 Execution timed out 2040 ms 5876 KB Time limit exceeded
51 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 46 ms 4220 KB Output is correct
10 Correct 13 ms 1528 KB Output is correct
11 Correct 30 ms 3064 KB Output is correct
12 Correct 33 ms 3448 KB Output is correct
13 Correct 40 ms 3704 KB Output is correct
14 Correct 26 ms 2812 KB Output is correct
15 Correct 7 ms 888 KB Output is correct
16 Correct 27 ms 2808 KB Output is correct
17 Correct 64 ms 5496 KB Output is correct
18 Correct 37 ms 3448 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 4 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 3 ms 388 KB Output is correct
31 Correct 4 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 3 ms 248 KB Output is correct
34 Correct 32 ms 2168 KB Output is correct
35 Correct 53 ms 4572 KB Output is correct
36 Correct 112 ms 5964 KB Output is correct
37 Correct 633 ms 5580 KB Output is correct
38 Correct 708 ms 6224 KB Output is correct
39 Correct 53 ms 5116 KB Output is correct
40 Correct 4 ms 376 KB Output is correct
41 Correct 92 ms 3088 KB Output is correct
42 Correct 101 ms 5496 KB Output is correct
43 Correct 20 ms 888 KB Output is correct
44 Correct 66 ms 3960 KB Output is correct
45 Correct 112 ms 4304 KB Output is correct
46 Correct 108 ms 5776 KB Output is correct
47 Correct 22 ms 2424 KB Output is correct
48 Correct 5 ms 508 KB Output is correct
49 Correct 514 ms 5332 KB Output is correct
50 Correct 113 ms 5700 KB Output is correct
51 Correct 266 ms 5332 KB Output is correct
52 Correct 111 ms 5496 KB Output is correct
53 Correct 69 ms 5904 KB Output is correct
54 Correct 575 ms 5688 KB Output is correct
55 Correct 61 ms 5244 KB Output is correct
56 Correct 193 ms 5376 KB Output is correct
57 Correct 102 ms 5240 KB Output is correct
58 Execution timed out 2040 ms 5876 KB Time limit exceeded
59 Halted 0 ms 0 KB -