답안 #164747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
164747 2019-11-23T06:57:02 Z quocnguyen1012 Bali Sculptures (APIO15_sculpture) C++14
50 / 100
297 ms 4732 KB
#include <bits/stdc++.h>

#define Task "A"
#define pb push_back
#define int long long

using namespace std;
typedef long long ll;

mt19937 rng (chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 2005;

int testbit (ll x, int n){
    return x >> n & 1;
}

int N;
int a[maxn];
ll sum[maxn];
ll dp[maxn];
int P, Q;

bool submask (ll mask1, ll mask2){
    return (mask1 & mask2) == mask1;
}

bool check (ll mask){
    for (int i=1; i<=N; ++i) dp[i] = 1e9;
    for (int i=1; i<=N; ++i){
        for (int j=i-1; j>=0; --j){
            if (dp[j] < 1e9 && submask (sum[i] - sum[j], mask)){
                dp[i] = min(dp[i], dp[j] + 1);
            }
        }
    }
    //cerr << f[N];
    return dp[N] <= Q;
}

int f[105][105][50];

ll solve (int l, int K){
    memset(f, -1, sizeof f);
    for (int i=1; i<=N; ++i){
        sum[i] = sum[i-1] + a[i];
        for (int j=0; j<=50; ++j){
            if (testbit (sum[i], j)) f[i][1][j] = sum[i];
        }
    }
    for (int i=2; i<=N; ++i){
        for (int j=2; j<=min(i, K); ++j){
            for (int z=0; z<=50; ++z){
                f[i][j][z] = 1e17;
                for (int t=i-1; t>=0; --t){
                    if (f[t][j-1][z] == -1) continue;
                    if (f[i][j][z] == -1) f[i][j][z] = f[t][j-1][z] | (sum[i] - sum[t]);
                    else
                        f[i][j][z] = min (f[i][j][z], f[t][j-1][z] | (sum[i] - sum[t]));
                }
            }
        }
    }
    ll ans = 1e15;
    for (int j=l; j<=K; ++j)
        for (int i=0; i<=35; ++i)
            if (f[N][j][i] != -1)
                ans = min (ans, f[N][j][i]);
    return ans;
}
signed main (void){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen (Task".inp", "r")){
        freopen (Task".inp", "r", stdin);
        freopen (Task".out", "w", stdout);
    }
    cin >> N >> P >> Q;
    for (int i=1; i<=N; ++i){
        cin >> a[i];
        sum[i] = sum[i-1] + a[i];
    }

    if (P == 1){
        ll ans = (1ll << 62) - 1;
        for (int i=61; i>=0; --i){
            if (check (ans -(1ll << i)))
                ans -= (1ll << i);
            ///cerr << ans << '\n';
        }
        cout << ans;
    }
    else{
        cout << solve(P, Q);
    }
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:74:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen (Task".inp", "r", stdin);
         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:75:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen (Task".out", "w", stdout);
         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp: In function 'll solve(long long int, long long int)':
sculpture.cpp:54:28: warning: iteration 50 invokes undefined behavior [-Waggressive-loop-optimizations]
                 f[i][j][z] = 1e17;
                 ~~~~~~~~~~~^~~~~~
sculpture.cpp:53:28: note: within this loop
             for (int z=0; z<=50; ++z){
                           ~^~~~
# 결과 실행 시간 메모리 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 2 ms 376 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 6 ms 4728 KB Output is correct
15 Incorrect 6 ms 4728 KB Output isn't correct
16 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 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 6 ms 4732 KB Output is correct
15 Incorrect 6 ms 4728 KB Output isn't correct
16 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 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 4 ms 504 KB Output is correct
12 Correct 2 ms 380 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 376 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 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 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 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 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 2 ms 376 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 6 ms 4600 KB Output is correct
15 Incorrect 22 ms 4728 KB Output isn't correct
16 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 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 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 380 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 376 KB Output is correct
17 Correct 1 ms 376 KB Output is correct
18 Correct 2 ms 380 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 376 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 252 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 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 3 ms 376 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 3 ms 376 KB Output is correct
39 Correct 3 ms 376 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 3 ms 376 KB Output is correct
42 Correct 3 ms 380 KB Output is correct
43 Correct 2 ms 376 KB Output is correct
44 Correct 3 ms 380 KB Output is correct
45 Correct 3 ms 376 KB Output is correct
46 Correct 3 ms 376 KB Output is correct
47 Correct 3 ms 348 KB Output is correct
48 Correct 3 ms 376 KB Output is correct
49 Correct 3 ms 380 KB Output is correct
50 Correct 3 ms 376 KB Output is correct
51 Correct 3 ms 376 KB Output is correct
52 Correct 29 ms 376 KB Output is correct
53 Correct 36 ms 376 KB Output is correct
54 Correct 79 ms 376 KB Output is correct
55 Correct 92 ms 376 KB Output is correct
56 Correct 244 ms 376 KB Output is correct
57 Correct 234 ms 376 KB Output is correct
58 Correct 243 ms 376 KB Output is correct
59 Correct 270 ms 504 KB Output is correct
60 Correct 254 ms 440 KB Output is correct
61 Correct 3 ms 380 KB Output is correct
62 Correct 38 ms 380 KB Output is correct
63 Correct 77 ms 504 KB Output is correct
64 Correct 65 ms 376 KB Output is correct
65 Correct 219 ms 376 KB Output is correct
66 Correct 178 ms 376 KB Output is correct
67 Correct 235 ms 380 KB Output is correct
68 Correct 297 ms 476 KB Output is correct
69 Correct 233 ms 376 KB Output is correct