Submission #43748

# Submission time Handle Problem Language Result Execution time Memory
43748 2018-03-22T03:47:25 Z nickyrio Chessboard (IZhO18_chessboard) C++14
70 / 100
2000 ms 262144 KB
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (int i = (a); i >= (b); --i)
#define REP(i, a) for (int i = 0; i < (a); ++i)
#define DEBUG(x) { cerr << #x << '=' << x << endl; }
#define Arr(a, l, r) { cerr << #a << " = {"; FOR(_, l, r) cerr << ' ' << a[_]; cerr << "}\n"; }
#define N 1001000
#define pp pair<int, int>
#define endl '\n'
#define IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define taskname ""
#define bit(S, i) (((S) >> (i)) & 1)
using namespace std;
long long n, k, xx1[N], xx2[N], xy1[N], xy2[N];

long long cal(int l, int color, int x1, int y1, int x2, int y2) {
    if (x2 < x1 || y2 < y1) return 0;
    int mx1 = (x1 - 1 + l) / l * l, mx2 = (x2 + 1) / l * l - 1;
    int my1 = (y1 - 1 + l) / l * l, my2 = (y2 + 1) / l * l - 1;
    if (x1 / l == x2 / l) {
        if (y1 / l == y2 / l) {
            if (color ^ (((x1 / l) % 2) == (y1 / l) % 2)) return - 1ll * (x2 - x1 + 1) * (y2 - y1 + 1);
            return 1ll * (x2 - x1 + 1) * (y2 - y1 + 1);
        }
        if (my1 == y1 && my2 == y2) {
            int sz = (y2 + 1 - y1) / l;
            if (sz % 2 == 0) return 0;
            if (color ^ (((x1 / l) % 2) == (y1 / l) % 2)) return - 1ll * (x2 - x1 + 1) * l;
            return 1ll * (x2 - x1 + 1) * l;;
        }
        return cal(l, color, x1, y1, x2, my1 - 1)
            +  cal(l, color, x1, my1, x2, my2)
            +  cal(l, color, x1, my2 + 1, x2, y2);
    }
    if (mx1 == x1 && mx2 == x2 && y1 == my1 && y2 == my2) {
        int sz = (y2 + 1 - y1) / l * (x2 + 1 - x1) / l;
        if (sz % 2 == 0) return 0;
        if (color ^ (((x1 / l) % 2) == (y1 / l) % 2)) return - 1ll * l * l;
        return l * l;    
    }
    return cal(l, color, x1, y1, mx1 - 1, y2)
        + cal(l, color, mx1, y1, mx2, y2) 
        + cal(l, color, mx2 + 1, y1, x2, y2);
}
long long solve(int l, int color) {// color = 0 -> Top-left is black
    long long ans = ((1ll * (n / l) * (n / l) + 1 - color) / 2) * l * l ;
    /*REP(i, k) {
        if (color ^ (((xx1[i] / l) % 2) == (xy1[i] / l) % 2)) ans--;
        else ans++;
    }*/
    REP(i, k) {
        ans += cal(l, color, xx1[i], xy1[i], xx2[i], xy2[i]);
    }
    return ans;
} 
int main() {
    #ifdef NERO
    freopen("test.inp","r",stdin);
    freopen("test.out","w",stdout);
    clock_t stime = clock();
    #endif //NERO
    scanf("%d %d", &n, &k);
    long long ans = 1e10;
    REP(i, k) scanf("%d %d %d %d", &xx1[i], &xy1[i], &xx2[i], &xy2[i]);
    REP(i, k) xx1[i]--,xx2[i]--,xy1[i]--,xy2[i]--;
    FOR(i, 1, sqrt(n)) if (n % i == 0) {
        ans = min(ans, solve(i, 0));
        ans = min(ans, solve(i, 1));
        if (i != 1) ans = min(ans, solve(n / i, 0));
        if (i != 1) ans = min(ans, solve(n / i, 1));
    }
    printf("%lld", ans);
    #ifdef NERO
    clock_t etime = clock();
    cerr << "Execution time: " << (etime - stime) / CLOCKS_PER_SEC * 1000 << " ms.";
    #endif // NERO
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:62:26: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
     scanf("%d %d", &n, &k);
                          ^
chessboard.cpp:62:26: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
chessboard.cpp:64:70: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
     REP(i, k) scanf("%d %d %d %d", &xx1[i], &xy1[i], &xx2[i], &xy2[i]);
                                                                      ^
chessboard.cpp:64:70: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
chessboard.cpp:64:70: warning: format '%d' expects argument of type 'int*', but argument 4 has type 'long long int*' [-Wformat=]
chessboard.cpp:64:70: warning: format '%d' expects argument of type 'int*', but argument 5 has type 'long long int*' [-Wformat=]
chessboard.cpp:62:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &k);
                           ^
chessboard.cpp:64:71: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     REP(i, k) scanf("%d %d %d %d", &xx1[i], &xy1[i], &xx2[i], &xy2[i]);
                                                                       ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 2 ms 404 KB Output is correct
4 Correct 1 ms 476 KB Output is correct
5 Correct 1 ms 612 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2624 KB Output is correct
2 Correct 17 ms 2624 KB Output is correct
3 Correct 42 ms 2624 KB Output is correct
4 Correct 44 ms 2624 KB Output is correct
5 Correct 44 ms 2624 KB Output is correct
6 Correct 25 ms 2624 KB Output is correct
7 Correct 5 ms 2624 KB Output is correct
8 Correct 32 ms 2624 KB Output is correct
9 Correct 61 ms 3436 KB Output is correct
10 Correct 30 ms 3436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3436 KB Output is correct
2 Correct 1 ms 3436 KB Output is correct
3 Correct 2 ms 3436 KB Output is correct
4 Correct 3 ms 3436 KB Output is correct
5 Correct 3 ms 3436 KB Output is correct
6 Correct 2 ms 3436 KB Output is correct
7 Correct 2 ms 3436 KB Output is correct
8 Correct 3 ms 3436 KB Output is correct
9 Correct 2 ms 3436 KB Output is correct
10 Correct 1 ms 3436 KB Output is correct
11 Correct 2 ms 3436 KB Output is correct
12 Correct 2 ms 3436 KB Output is correct
13 Correct 2 ms 3436 KB Output is correct
14 Correct 2 ms 3436 KB Output is correct
15 Correct 2 ms 3436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3436 KB Output is correct
2 Correct 1 ms 3436 KB Output is correct
3 Correct 2 ms 3436 KB Output is correct
4 Correct 3 ms 3436 KB Output is correct
5 Correct 3 ms 3436 KB Output is correct
6 Correct 2 ms 3436 KB Output is correct
7 Correct 2 ms 3436 KB Output is correct
8 Correct 3 ms 3436 KB Output is correct
9 Correct 2 ms 3436 KB Output is correct
10 Correct 1 ms 3436 KB Output is correct
11 Correct 2 ms 3436 KB Output is correct
12 Correct 2 ms 3436 KB Output is correct
13 Correct 2 ms 3436 KB Output is correct
14 Correct 2 ms 3436 KB Output is correct
15 Correct 2 ms 3436 KB Output is correct
16 Correct 27 ms 3436 KB Output is correct
17 Correct 42 ms 3436 KB Output is correct
18 Correct 62 ms 3744 KB Output is correct
19 Correct 207 ms 3744 KB Output is correct
20 Correct 228 ms 3820 KB Output is correct
21 Correct 40 ms 3820 KB Output is correct
22 Correct 2 ms 3820 KB Output is correct
23 Correct 39 ms 3820 KB Output is correct
24 Correct 58 ms 3820 KB Output is correct
25 Correct 9 ms 3820 KB Output is correct
26 Correct 37 ms 3820 KB Output is correct
27 Correct 53 ms 3820 KB Output is correct
28 Correct 60 ms 3820 KB Output is correct
29 Correct 17 ms 3820 KB Output is correct
30 Correct 3 ms 3820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2624 KB Output is correct
2 Correct 17 ms 2624 KB Output is correct
3 Correct 42 ms 2624 KB Output is correct
4 Correct 44 ms 2624 KB Output is correct
5 Correct 44 ms 2624 KB Output is correct
6 Correct 25 ms 2624 KB Output is correct
7 Correct 5 ms 2624 KB Output is correct
8 Correct 32 ms 2624 KB Output is correct
9 Correct 61 ms 3436 KB Output is correct
10 Correct 30 ms 3436 KB Output is correct
11 Correct 2 ms 3436 KB Output is correct
12 Correct 1 ms 3436 KB Output is correct
13 Correct 2 ms 3436 KB Output is correct
14 Correct 3 ms 3436 KB Output is correct
15 Correct 3 ms 3436 KB Output is correct
16 Correct 2 ms 3436 KB Output is correct
17 Correct 2 ms 3436 KB Output is correct
18 Correct 3 ms 3436 KB Output is correct
19 Correct 2 ms 3436 KB Output is correct
20 Correct 1 ms 3436 KB Output is correct
21 Correct 2 ms 3436 KB Output is correct
22 Correct 2 ms 3436 KB Output is correct
23 Correct 2 ms 3436 KB Output is correct
24 Correct 2 ms 3436 KB Output is correct
25 Correct 2 ms 3436 KB Output is correct
26 Correct 27 ms 3436 KB Output is correct
27 Correct 42 ms 3436 KB Output is correct
28 Correct 62 ms 3744 KB Output is correct
29 Correct 207 ms 3744 KB Output is correct
30 Correct 228 ms 3820 KB Output is correct
31 Correct 40 ms 3820 KB Output is correct
32 Correct 2 ms 3820 KB Output is correct
33 Correct 39 ms 3820 KB Output is correct
34 Correct 58 ms 3820 KB Output is correct
35 Correct 9 ms 3820 KB Output is correct
36 Correct 37 ms 3820 KB Output is correct
37 Correct 53 ms 3820 KB Output is correct
38 Correct 60 ms 3820 KB Output is correct
39 Correct 17 ms 3820 KB Output is correct
40 Correct 3 ms 3820 KB Output is correct
41 Correct 189 ms 3820 KB Output is correct
42 Correct 71 ms 3820 KB Output is correct
43 Correct 110 ms 3820 KB Output is correct
44 Correct 71 ms 3820 KB Output is correct
45 Correct 56 ms 3820 KB Output is correct
46 Correct 199 ms 3820 KB Output is correct
47 Correct 67 ms 3820 KB Output is correct
48 Correct 86 ms 3820 KB Output is correct
49 Correct 60 ms 3820 KB Output is correct
50 Correct 917 ms 3820 KB Output is correct
51 Correct 972 ms 3820 KB Output is correct
52 Correct 900 ms 3820 KB Output is correct
53 Correct 911 ms 3820 KB Output is correct
54 Correct 838 ms 3820 KB Output is correct
55 Correct 939 ms 3820 KB Output is correct
56 Correct 822 ms 3820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 2 ms 404 KB Output is correct
4 Correct 1 ms 476 KB Output is correct
5 Correct 1 ms 612 KB Output is correct
6 Correct 2 ms 620 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 2 ms 620 KB Output is correct
9 Correct 38 ms 2624 KB Output is correct
10 Correct 17 ms 2624 KB Output is correct
11 Correct 42 ms 2624 KB Output is correct
12 Correct 44 ms 2624 KB Output is correct
13 Correct 44 ms 2624 KB Output is correct
14 Correct 25 ms 2624 KB Output is correct
15 Correct 5 ms 2624 KB Output is correct
16 Correct 32 ms 2624 KB Output is correct
17 Correct 61 ms 3436 KB Output is correct
18 Correct 30 ms 3436 KB Output is correct
19 Correct 2 ms 3436 KB Output is correct
20 Correct 1 ms 3436 KB Output is correct
21 Correct 2 ms 3436 KB Output is correct
22 Correct 3 ms 3436 KB Output is correct
23 Correct 3 ms 3436 KB Output is correct
24 Correct 2 ms 3436 KB Output is correct
25 Correct 2 ms 3436 KB Output is correct
26 Correct 3 ms 3436 KB Output is correct
27 Correct 2 ms 3436 KB Output is correct
28 Correct 1 ms 3436 KB Output is correct
29 Correct 2 ms 3436 KB Output is correct
30 Correct 2 ms 3436 KB Output is correct
31 Correct 2 ms 3436 KB Output is correct
32 Correct 2 ms 3436 KB Output is correct
33 Correct 2 ms 3436 KB Output is correct
34 Correct 27 ms 3436 KB Output is correct
35 Correct 42 ms 3436 KB Output is correct
36 Correct 62 ms 3744 KB Output is correct
37 Correct 207 ms 3744 KB Output is correct
38 Correct 228 ms 3820 KB Output is correct
39 Correct 40 ms 3820 KB Output is correct
40 Correct 2 ms 3820 KB Output is correct
41 Correct 39 ms 3820 KB Output is correct
42 Correct 58 ms 3820 KB Output is correct
43 Correct 9 ms 3820 KB Output is correct
44 Correct 37 ms 3820 KB Output is correct
45 Correct 53 ms 3820 KB Output is correct
46 Correct 60 ms 3820 KB Output is correct
47 Correct 17 ms 3820 KB Output is correct
48 Correct 3 ms 3820 KB Output is correct
49 Correct 189 ms 3820 KB Output is correct
50 Correct 71 ms 3820 KB Output is correct
51 Correct 110 ms 3820 KB Output is correct
52 Correct 71 ms 3820 KB Output is correct
53 Correct 56 ms 3820 KB Output is correct
54 Correct 199 ms 3820 KB Output is correct
55 Correct 67 ms 3820 KB Output is correct
56 Correct 86 ms 3820 KB Output is correct
57 Correct 60 ms 3820 KB Output is correct
58 Correct 917 ms 3820 KB Output is correct
59 Correct 972 ms 3820 KB Output is correct
60 Correct 900 ms 3820 KB Output is correct
61 Correct 911 ms 3820 KB Output is correct
62 Correct 838 ms 3820 KB Output is correct
63 Correct 939 ms 3820 KB Output is correct
64 Correct 822 ms 3820 KB Output is correct
65 Correct 2 ms 3820 KB Output is correct
66 Correct 2 ms 3820 KB Output is correct
67 Execution timed out 2107 ms 262144 KB Time limit exceeded
68 Halted 0 ms 0 KB -