Submission #133419

# Submission time Handle Problem Language Result Execution time Memory
133419 2019-07-20T14:56:41 Z Kastanda Chessboard (IZhO18_chessboard) C++11
100 / 100
228 ms 5084 KB
// ItnoE
#include<bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int N = 100005;
int n, k, dp[N], dp2[N];
pair < int , int > A[N], B[N];
inline long long Solve(int d)
{
    long long tot = n / d;
    tot *= tot; tot = (tot + 1) >> 1;
    tot *= 1LL * d * d;
    for (int i = 1; i <= n; i ++)
        dp[i] = dp[i - 1] + ((i - 1) / d % 2 == 0), dp2[i] = i - dp[i];
    for (int i = 0; i < k; i ++)
    {
        int ax = dp[B[i].first] - dp[A[i].first];
        int bx = dp2[B[i].first] - dp2[A[i].first];
        int ay = dp[B[i].second] - dp[A[i].second];
        int by = dp2[B[i].second] - dp2[A[i].second];
        tot -= 1LL * ax * ay;
        tot -= 1LL * bx * by;
        tot += 1LL * ax * by;
        tot += 1LL * bx * ay;
    }
    return (min(tot, 1LL * n * n - tot));
}
int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 0; i < k; i ++)
        scanf("%d%d%d%d", &A[i].x, &A[i].y, &B[i].x, &B[i].y), A[i].x --, A[i].y --;
    long long Mn = LLONG_MAX;
    for (int d = 1; d < n; d ++)
        if (n % d == 0)
            Mn = min(Mn, Solve(d));
    return !printf("%lld\n", Mn);
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~
chessboard.cpp:33:73: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d", &A[i].x, &A[i].y, &B[i].x, &B[i].y), A[i].x --, A[i].y --;
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# Verdict Execution time Memory 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 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 3284 KB Output is correct
2 Correct 10 ms 1012 KB Output is correct
3 Correct 23 ms 2552 KB Output is correct
4 Correct 23 ms 1912 KB Output is correct
5 Correct 30 ms 2908 KB Output is correct
6 Correct 20 ms 2012 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 21 ms 2168 KB Output is correct
9 Correct 47 ms 4088 KB Output is correct
10 Correct 28 ms 2552 KB Output is correct
# Verdict Execution time Memory 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 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory 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 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 14 ms 1144 KB Output is correct
17 Correct 37 ms 3192 KB Output is correct
18 Correct 43 ms 3448 KB Output is correct
19 Correct 47 ms 3196 KB Output is correct
20 Correct 52 ms 3448 KB Output is correct
21 Correct 36 ms 2940 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 21 ms 1656 KB Output is correct
24 Correct 40 ms 3192 KB Output is correct
25 Correct 6 ms 632 KB Output is correct
26 Correct 26 ms 2168 KB Output is correct
27 Correct 31 ms 2552 KB Output is correct
28 Correct 42 ms 3420 KB Output is correct
29 Correct 17 ms 1400 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 3284 KB Output is correct
2 Correct 10 ms 1012 KB Output is correct
3 Correct 23 ms 2552 KB Output is correct
4 Correct 23 ms 1912 KB Output is correct
5 Correct 30 ms 2908 KB Output is correct
6 Correct 20 ms 2012 KB Output is correct
7 Correct 6 ms 760 KB Output is correct
8 Correct 21 ms 2168 KB Output is correct
9 Correct 47 ms 4088 KB Output is correct
10 Correct 28 ms 2552 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 14 ms 1144 KB Output is correct
27 Correct 37 ms 3192 KB Output is correct
28 Correct 43 ms 3448 KB Output is correct
29 Correct 47 ms 3196 KB Output is correct
30 Correct 52 ms 3448 KB Output is correct
31 Correct 36 ms 2940 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 21 ms 1656 KB Output is correct
34 Correct 40 ms 3192 KB Output is correct
35 Correct 6 ms 632 KB Output is correct
36 Correct 26 ms 2168 KB Output is correct
37 Correct 31 ms 2552 KB Output is correct
38 Correct 42 ms 3420 KB Output is correct
39 Correct 17 ms 1400 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 76 ms 4424 KB Output is correct
42 Correct 54 ms 4856 KB Output is correct
43 Correct 60 ms 4344 KB Output is correct
44 Correct 54 ms 4728 KB Output is correct
45 Correct 53 ms 4984 KB Output is correct
46 Correct 82 ms 4828 KB Output is correct
47 Correct 47 ms 4472 KB Output is correct
48 Correct 56 ms 4472 KB Output is correct
49 Correct 49 ms 4472 KB Output is correct
50 Correct 210 ms 4600 KB Output is correct
51 Correct 228 ms 4856 KB Output is correct
52 Correct 222 ms 4600 KB Output is correct
53 Correct 222 ms 4856 KB Output is correct
54 Correct 214 ms 4472 KB Output is correct
55 Correct 228 ms 4984 KB Output is correct
56 Correct 201 ms 4456 KB Output is correct
# Verdict Execution time Memory 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 376 KB Output is correct
9 Correct 34 ms 3284 KB Output is correct
10 Correct 10 ms 1012 KB Output is correct
11 Correct 23 ms 2552 KB Output is correct
12 Correct 23 ms 1912 KB Output is correct
13 Correct 30 ms 2908 KB Output is correct
14 Correct 20 ms 2012 KB Output is correct
15 Correct 6 ms 760 KB Output is correct
16 Correct 21 ms 2168 KB Output is correct
17 Correct 47 ms 4088 KB Output is correct
18 Correct 28 ms 2552 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 380 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 380 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 3 ms 376 KB Output is correct
34 Correct 14 ms 1144 KB Output is correct
35 Correct 37 ms 3192 KB Output is correct
36 Correct 43 ms 3448 KB Output is correct
37 Correct 47 ms 3196 KB Output is correct
38 Correct 52 ms 3448 KB Output is correct
39 Correct 36 ms 2940 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 21 ms 1656 KB Output is correct
42 Correct 40 ms 3192 KB Output is correct
43 Correct 6 ms 632 KB Output is correct
44 Correct 26 ms 2168 KB Output is correct
45 Correct 31 ms 2552 KB Output is correct
46 Correct 42 ms 3420 KB Output is correct
47 Correct 17 ms 1400 KB Output is correct
48 Correct 3 ms 504 KB Output is correct
49 Correct 76 ms 4424 KB Output is correct
50 Correct 54 ms 4856 KB Output is correct
51 Correct 60 ms 4344 KB Output is correct
52 Correct 54 ms 4728 KB Output is correct
53 Correct 53 ms 4984 KB Output is correct
54 Correct 82 ms 4828 KB Output is correct
55 Correct 47 ms 4472 KB Output is correct
56 Correct 56 ms 4472 KB Output is correct
57 Correct 49 ms 4472 KB Output is correct
58 Correct 210 ms 4600 KB Output is correct
59 Correct 228 ms 4856 KB Output is correct
60 Correct 222 ms 4600 KB Output is correct
61 Correct 222 ms 4856 KB Output is correct
62 Correct 214 ms 4472 KB Output is correct
63 Correct 228 ms 4984 KB Output is correct
64 Correct 201 ms 4456 KB Output is correct
65 Correct 2 ms 500 KB Output is correct
66 Correct 2 ms 376 KB Output is correct
67 Correct 215 ms 4720 KB Output is correct
68 Correct 218 ms 4672 KB Output is correct
69 Correct 191 ms 4248 KB Output is correct
70 Correct 181 ms 4600 KB Output is correct
71 Correct 193 ms 4600 KB Output is correct
72 Correct 186 ms 4476 KB Output is correct
73 Correct 205 ms 4304 KB Output is correct
74 Correct 209 ms 4728 KB Output is correct
75 Correct 192 ms 4508 KB Output is correct
76 Correct 212 ms 4744 KB Output is correct
77 Correct 75 ms 4940 KB Output is correct
78 Correct 53 ms 4600 KB Output is correct
79 Correct 61 ms 4472 KB Output is correct
80 Correct 64 ms 4604 KB Output is correct
81 Correct 59 ms 4404 KB Output is correct
82 Correct 59 ms 4728 KB Output is correct
83 Correct 53 ms 4444 KB Output is correct
84 Correct 153 ms 5056 KB Output is correct
85 Correct 224 ms 4956 KB Output is correct
86 Correct 51 ms 1016 KB Output is correct
87 Correct 49 ms 1016 KB Output is correct
88 Correct 224 ms 5084 KB Output is correct
89 Correct 82 ms 1696 KB Output is correct
90 Correct 50 ms 1016 KB Output is correct