답안 #866960

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866960 2023-10-27T13:55:14 Z tothanhdat1421 Bali Sculptures (APIO15_sculpture) C++14
100 / 100
91 ms 600 KB
/* ========================  INCL  ======================== */
#include <iostream>
#include <fstream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

using namespace std;

/* Code by { To Thanh Dat } 12TT THPT Chuyen Ben Tre */

/* ========================TEMPLATE======================== */
#define ll  long long
#define ull unsigned long long
#define pii pair<int, int>
#define vi  vector<int>
#define vii vector<pair<int, int>>
#define mii map<int, int>
#define pb  push_back
#define eb  emplace_back
#define mp  make_pair
#define fi  first
#define se  second

#define For(i, a, b)   for(int i=a; i<=b; ++i)
#define rFor(i, a, b)  for(int i=a; i>=b; --i)
#define Rep(i, n)      for(int i = 0; i < (int)n; ++i)
#define rRep(i, n)     for(int i = (int)n - 1; i >= 0; --i)

/* ========================CONSTANT======================== */
const int intINF = -1 ^ (1<<31);
const ll llINF = -1LL ^ (1LL << 63);
const int mod = 1e9+7;
const int N = 2000+5;

/* ========================VARIABLE======================== */
int n, A, B;
ll a[N];
int F[N];
bool F2[105][105];

/* ========================  MAIN  ======================== */
bool can(ll mask)
{
    For(i, 1, n+1) F[i] = 1e5;
    F[1] = 0;

    For(i, 1, n)
    {
        if(F[i] >= 1e5) continue;
        ll cursum = 0;
        For(j, i, n)
        {
            cursum += a[j];
            if((cursum & mask) == 0)
            {
                F[j+1] = min(F[j+1], 1 + F[i]);
            }
        }
    }

    // cout << "mask = " << mask << endl;
    // For(i, 0, n) cout << F[i] << ' ';
    // cout << endl;

    return (A <= F[n+1] && F[n+1] <= B);
}

bool can2(ll mask)
{
    For(i, 0, n+1) For(j, 0, n+1) F2[i][j] = 0;
    F2[1][1] = 1;

    For(j, 0, B)
    {
        For(i, 1, n)
        {
            if(F2[i][j])
            {
                ll cur_sum = 0;
                For(k, i, n)
                {
                    cur_sum += a[k];
                    if((cur_sum & mask) == 0)
                    {
                        F2[k+1][j+1] = 1;
                    }
                }
            }
        }
    }

    For(i, A, B)
    {
        if(F2[n+1][i+1]) return 1;
    }
    return 0;
}

int main()
{
    if(fopen("APIO15_sculpture.inp", "r"))
    {
        freopen("APIO15_sculpture.inp", "r", stdin);
        freopen("APIO15_sculpture.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    
    cin >> n >> A >> B;
    For(i, 1, n) cin >> a[i];
    // pref[0] = 0;
    // For(i, 1, n) pref[i] = pref[i-1] + a[i];    

    ll cur_mask = 0;
    rFor(i, 60, 0)
    {
        if(A == 1)
        {
            if(can(cur_mask | (1ll << i)))
            {
                cur_mask = cur_mask | (1ll << i);
                // cout << "   => cur mask = " << cur_mask << endl;
            }
        }
        else
        {
            if(can2(cur_mask | (1ll << i)))
            {
                cur_mask = cur_mask | (1ll << i);
                // cout << "   => cur mask = " << cur_mask << endl;
            }
        }
    }

    cout << ((1ll << 61)-1 - cur_mask);
    return 0;
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:108:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |         freopen("APIO15_sculpture.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:109:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |         freopen("APIO15_sculpture.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 504 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 388 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 536 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 600 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 1 ms 344 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 6 ms 348 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 348 KB Output is correct
67 Correct 2 ms 348 KB Output is correct
68 Correct 3 ms 348 KB Output is correct
69 Correct 4 ms 348 KB Output is correct
70 Correct 5 ms 344 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 5 ms 348 KB Output is correct
73 Correct 5 ms 344 KB Output is correct
74 Correct 5 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 600 KB Output is correct
10 Correct 0 ms 600 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 468 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 7 ms 344 KB Output is correct
53 Correct 8 ms 348 KB Output is correct
54 Correct 24 ms 480 KB Output is correct
55 Correct 19 ms 344 KB Output is correct
56 Correct 53 ms 348 KB Output is correct
57 Correct 50 ms 348 KB Output is correct
58 Correct 58 ms 344 KB Output is correct
59 Correct 70 ms 344 KB Output is correct
60 Correct 60 ms 348 KB Output is correct
61 Correct 1 ms 348 KB Output is correct
62 Correct 8 ms 348 KB Output is correct
63 Correct 24 ms 348 KB Output is correct
64 Correct 13 ms 344 KB Output is correct
65 Correct 25 ms 348 KB Output is correct
66 Correct 38 ms 348 KB Output is correct
67 Correct 52 ms 348 KB Output is correct
68 Correct 91 ms 348 KB Output is correct
69 Correct 50 ms 344 KB Output is correct