답안 #744185

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
744185 2023-05-18T09:02:03 Z fanwen Bali Sculptures (APIO15_sculpture) C++17
71 / 100
46 ms 848 KB
#include <bits/stdc++.h>

using namespace std;

#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()

#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(it, s) for (__typeof(s.begin()) it = (s).begin(); it != (s).end(); ++it)

#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
#define file(TASK)                         \
    if (fopen(TASK ".inp", "r")) {         \
        freopen(TASK ".inp", "r", stdin);  \
        freopen(TASK ".out", "w", stdout); \
    }

template <class U, class V> bool maximize(U &A, const V &B) { return (A < B) ? (A = B, true) : false; }
template <class U, class V> bool minimize(U &A, const V &B) { return (A > B) ? (A = B, true) : false; }

const int MAXN = 2e3 + 5;

int N, L, R, dp[MAXN][MAXN];
long long a[MAXN];

namespace sub1 {

    void Main() {
        long long ans = 0;
        FORD(bit, 40, 0) {
            long long mask = ans + MASK(bit) - 1;
            FOR(i, 0, N) FOR(x, 0, R) dp[i][x] = 0;
            dp[0][0] = 1;
            FOR(i, 1, N) FOR(j, 1, R) FOR(k, 1, i) {
                long long sum = a[i] - a[k - 1];
                if((sum & mask) == sum) dp[i][j] |= dp[k - 1][j - 1];
            }
            bool check = 0;
            FOR(i, L, R) check |= dp[N][i];
            if(check == 0) ans |= MASK(bit);
        }
        cout << ans;
        exit(0);
    }
}


namespace sub2 {

    void Main() {

        long long ans = 0;
        vector <int> F(N + 1);
        FORD(bit, 40, 0) {
            long long mask = ans + MASK(bit) - 1;
            fill(ALL(F), N + 1);
            F[0] = 0;
            FOR(i, 1, N) FOR(j, 1, i) {
                long long sum = a[i] - a[j - 1];
                if((sum & mask) == sum) minimize(F[i], F[j - 1] + 1);
            }
            if(F[N] >= R) ans |= MASK(bit);
        }

        cout << ans; exit(0);
    }
}
void process(void) {

    cin >> N >> L >> R;

    FOR(i, 1, N) cin >> a[i], a[i] += a[i - 1];

    if(N <= 100) sub1::Main();
    sub2::Main();
}
signed main() {
    file("TASK");
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int test = 1;
    // cin >> test;
    while(test--) {
        process();
        cout << '\n';
    }
    cerr << "Time elapsed: " << TIME << " s.\n";
    return (0 ^ 0);
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen(TASK ".inp", "r", stdin);  \
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:81:5: note: in expansion of macro 'file'
   81 |     file("TASK");
      |     ^~~~
sculpture.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen(TASK ".out", "w", stdout); \
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:81:5: note: in expansion of macro 'file'
   81 |     file("TASK");
      |     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 0 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 3 ms 476 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 3 ms 468 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 2 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 8 ms 596 KB Output is correct
27 Correct 18 ms 596 KB Output is correct
28 Correct 36 ms 748 KB Output is correct
29 Correct 43 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 19 ms 724 KB Output is correct
32 Correct 27 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 368 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 352 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 468 KB Output is correct
40 Correct 2 ms 468 KB Output is correct
41 Correct 3 ms 468 KB Output is correct
42 Correct 4 ms 468 KB Output is correct
43 Correct 1 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 532 KB Output is correct
46 Correct 1 ms 468 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 2 ms 596 KB Output is correct
49 Correct 6 ms 596 KB Output is correct
50 Correct 17 ms 712 KB Output is correct
51 Correct 37 ms 724 KB Output is correct
52 Correct 40 ms 768 KB Output is correct
53 Correct 1 ms 724 KB Output is correct
54 Correct 18 ms 724 KB Output is correct
55 Correct 28 ms 724 KB Output is correct
56 Correct 2 ms 468 KB Output is correct
57 Correct 5 ms 596 KB Output is correct
58 Correct 14 ms 724 KB Output is correct
59 Correct 35 ms 752 KB Output is correct
60 Correct 30 ms 724 KB Output is correct
61 Correct 1 ms 724 KB Output is correct
62 Correct 40 ms 724 KB Output is correct
63 Correct 34 ms 760 KB Output is correct
64 Correct 27 ms 724 KB Output is correct
65 Correct 2 ms 468 KB Output is correct
66 Correct 3 ms 584 KB Output is correct
67 Correct 5 ms 588 KB Output is correct
68 Correct 14 ms 716 KB Output is correct
69 Correct 28 ms 848 KB Output is correct
70 Correct 39 ms 640 KB Output is correct
71 Correct 1 ms 728 KB Output is correct
72 Correct 31 ms 724 KB Output is correct
73 Correct 24 ms 724 KB Output is correct
74 Correct 25 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 456 KB Output is correct
18 Correct 1 ms 404 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 352 KB Output is correct
26 Correct 1 ms 476 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 2 ms 472 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 1 ms 476 KB Output is correct
31 Correct 2 ms 468 KB Output is correct
32 Correct 2 ms 480 KB Output is correct
33 Correct 1 ms 468 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 6 ms 596 KB Output is correct
37 Correct 18 ms 720 KB Output is correct
38 Correct 46 ms 728 KB Output is correct
39 Correct 40 ms 764 KB Output is correct
40 Correct 1 ms 728 KB Output is correct
41 Correct 19 ms 748 KB Output is correct
42 Correct 29 ms 768 KB Output is correct
43 Correct 3 ms 480 KB Output is correct
44 Correct 5 ms 592 KB Output is correct
45 Correct 14 ms 720 KB Output is correct
46 Correct 29 ms 724 KB Output is correct
47 Correct 29 ms 724 KB Output is correct
48 Correct 1 ms 712 KB Output is correct
49 Correct 33 ms 756 KB Output is correct
50 Correct 30 ms 764 KB Output is correct
51 Incorrect 1 ms 212 KB Output isn't correct
52 Halted 0 ms 0 KB -