답안 #866957

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866957 2023-10-27T13:49:43 Z tothanhdat1421 Bali Sculptures (APIO15_sculpture) C++14
50 / 100
92 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, 1, n) For(j, 1, n) F2[i][j] = 0;

    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][i]) 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:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |         freopen("APIO15_sculpture.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:107:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  107 |         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 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 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 Incorrect 0 ms 348 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 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 Incorrect 1 ms 348 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 504 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 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 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 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 344 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 448 KB Output is correct
24 Correct 0 ms 344 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 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 344 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 344 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 344 KB Output is correct
10 Correct 1 ms 504 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 Incorrect 0 ms 348 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 360 KB Output is correct
6 Correct 1 ms 344 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 1 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 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 344 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 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 1 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 344 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 1 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 344 KB Output is correct
42 Correct 1 ms 600 KB Output is correct
43 Correct 0 ms 344 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 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 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 11 ms 344 KB Output is correct
53 Correct 8 ms 476 KB Output is correct
54 Correct 24 ms 344 KB Output is correct
55 Correct 18 ms 348 KB Output is correct
56 Correct 53 ms 348 KB Output is correct
57 Correct 50 ms 344 KB Output is correct
58 Correct 58 ms 348 KB Output is correct
59 Correct 79 ms 460 KB Output is correct
60 Correct 56 ms 348 KB Output is correct
61 Correct 1 ms 344 KB Output is correct
62 Correct 9 ms 348 KB Output is correct
63 Correct 24 ms 348 KB Output is correct
64 Correct 13 ms 348 KB Output is correct
65 Correct 25 ms 348 KB Output is correct
66 Correct 38 ms 348 KB Output is correct
67 Correct 50 ms 348 KB Output is correct
68 Correct 92 ms 348 KB Output is correct
69 Correct 49 ms 348 KB Output is correct