답안 #110231

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110231 2019-05-10T09:03:25 Z SamAnd Bali Sculptures (APIO15_sculpture) C++17
46 / 100
1000 ms 4524 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 2003, M = 102;

int n;
int ll, rr;
int a[N];

void solv0()
{
    long long ans = (1LL << 62);
    for (int x = 0; x < (1 << n); ++x)
    {
        if ((x & (1 << 0)) == 0)
            continue;
        vector<long long> v;
        long long y = a[1];
        for (int i = 1; i < n; ++i)
        {
            if ((x & (1 << i)))
            {
                v.push_back(y);
                y = a[i + 1];
            }
            else
                y += a[i + 1];
        }
        v.push_back(y);
        long long yans = 0;
        for (int i = 0; i < v.size(); ++i)
            yans = yans | v[i];
        if (ll <= v.size() && v.size() <= rr)
            ans = min(ans, yans);
    }
    cout << ans << endl;
}

void solv1()
{
    bool dp[M][M][1 << 12] = {};
    dp[0][0][0] = true;
    for (int i = 1; i <= n; ++i)
    {
        int s = 0;
        for (int j = i; j >= 1; --j)
        {
            s += a[j];
            for (int k = 0; k <= rr; ++k)
            {
                for (int x = 0; x < (1 << 12); ++x)
                {
                    if (!dp[j - 1][k][x])
                        continue;
                    dp[i][k + 1][x | s] = true;
                }
            }
        }
    }
    int ans = (1 << 12);
    for (int k = ll; k <= rr; ++k)
    {
        for (int x = 0; x < (1 << 12); ++x)
        {
            if (dp[n][k][x])
                ans = min(ans, x);
        }
    }
    cout << ans << endl;
}

void solv2()
{
    vector<long long> dp[M][M];
    dp[0][0].push_back(0);
    for (int i = 1; i <= n; ++i)
    {
        long long s = 0;
        for (int j = i; j >= 1; --j)
        {
            s += a[j];
            for (int k = 0; k <= rr; ++k)
            {
                for (int ii = 0; ii < dp[j - 1][k].size(); ++ii)
                {
                    long long x = (dp[j - 1][k][ii] | s);
                    bool z = false;
                    for (int jj = 0; jj < dp[i][k + 1].size(); ++jj)
                    {
                        if ((x | dp[i][k + 1][jj]) == x)
                        {
                            z = true;
                            break;
                        }
                    }
                    if (!z)
                        dp[i][k + 1].push_back(x);
                }
            }
        }
    }
    long long ans = (1LL << 62);
    for (int k = ll; k <= rr; ++k)
    {
        for (int ii = 0; ii < dp[n][k].size(); ++ii)
        {
            long long x = dp[n][k][ii];
            ans = min(ans, x);
        }
    }
    cout << ans << endl;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    cin >> n >> ll >> rr;
    for (int i = 1; i <= n; ++i)
        cin >> a[i];
    if (n <= 20)
        solv0();
    else
        solv2();
    return 0;
}

Compilation message

sculpture.cpp: In function 'void solv0()':
sculpture.cpp:30:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i = 0; i < v.size(); ++i)
                         ~~^~~~~~~~~~
sculpture.cpp:32:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (ll <= v.size() && v.size() <= rr)
             ~~~^~~~~~~~~~~
sculpture.cpp:32:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (ll <= v.size() && v.size() <= rr)
                               ~~~~~~~~~^~~~~
sculpture.cpp: In function 'void solv2()':
sculpture.cpp:83:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (int ii = 0; ii < dp[j - 1][k].size(); ++ii)
                                  ~~~^~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:87:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     for (int jj = 0; jj < dp[i][k + 1].size(); ++jj)
                                      ~~~^~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:104:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int ii = 0; ii < dp[n][k].size(); ++ii)
                          ~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 8 ms 304 KB Output is correct
7 Correct 31 ms 256 KB Output is correct
8 Correct 169 ms 384 KB Output is correct
9 Correct 178 ms 476 KB Output is correct
10 Correct 148 ms 256 KB Output is correct
11 Correct 189 ms 376 KB Output is correct
12 Correct 186 ms 256 KB Output is correct
13 Correct 155 ms 360 KB Output is correct
14 Correct 3 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 3 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 7 ms 256 KB Output is correct
20 Correct 24 ms 384 KB Output is correct
21 Correct 136 ms 384 KB Output is correct
22 Correct 143 ms 376 KB Output is correct
23 Correct 198 ms 504 KB Output is correct
24 Correct 158 ms 384 KB Output is correct
25 Correct 151 ms 356 KB Output is correct
26 Correct 149 ms 360 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 2 ms 256 KB Output is correct
29 Correct 4 ms 256 KB Output is correct
30 Correct 88 ms 256 KB Output is correct
31 Correct 143 ms 376 KB Output is correct
32 Correct 145 ms 364 KB Output is correct
33 Correct 137 ms 384 KB Output is correct
34 Correct 154 ms 384 KB Output is correct
35 Correct 144 ms 384 KB Output is correct
36 Correct 175 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 17 ms 384 KB Output is correct
7 Correct 23 ms 256 KB Output is correct
8 Correct 158 ms 384 KB Output is correct
9 Correct 135 ms 384 KB Output is correct
10 Correct 146 ms 384 KB Output is correct
11 Correct 148 ms 360 KB Output is correct
12 Correct 202 ms 476 KB Output is correct
13 Correct 212 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 256 KB Output is correct
19 Correct 8 ms 384 KB Output is correct
20 Correct 20 ms 384 KB Output is correct
21 Correct 168 ms 360 KB Output is correct
22 Correct 165 ms 476 KB Output is correct
23 Correct 160 ms 256 KB Output is correct
24 Correct 158 ms 356 KB Output is correct
25 Correct 170 ms 356 KB Output is correct
26 Correct 157 ms 256 KB Output is correct
27 Correct 3 ms 640 KB Output is correct
28 Correct 3 ms 640 KB Output is correct
29 Correct 3 ms 640 KB Output is correct
30 Correct 5 ms 640 KB Output is correct
31 Correct 15 ms 768 KB Output is correct
32 Correct 6 ms 640 KB Output is correct
33 Correct 2 ms 640 KB Output is correct
34 Correct 7 ms 768 KB Output is correct
35 Correct 7 ms 768 KB Output is correct
36 Correct 7 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 6 ms 256 KB Output is correct
7 Correct 20 ms 384 KB Output is correct
8 Correct 143 ms 384 KB Output is correct
9 Correct 142 ms 384 KB Output is correct
10 Correct 136 ms 256 KB Output is correct
11 Correct 164 ms 256 KB Output is correct
12 Correct 143 ms 360 KB Output is correct
13 Correct 143 ms 376 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 3 ms 640 KB Output is correct
17 Correct 5 ms 768 KB Output is correct
18 Correct 8 ms 768 KB Output is correct
19 Correct 5 ms 640 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 6 ms 768 KB Output is correct
22 Correct 5 ms 768 KB Output is correct
23 Correct 7 ms 640 KB Output is correct
24 Correct 9 ms 896 KB Output is correct
25 Correct 18 ms 896 KB Output is correct
26 Correct 47 ms 1500 KB Output is correct
27 Correct 107 ms 2272 KB Output is correct
28 Correct 183 ms 2760 KB Output is correct
29 Correct 78 ms 1940 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 187 ms 2936 KB Output is correct
32 Correct 223 ms 3180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 256 KB Output is correct
6 Correct 7 ms 384 KB Output is correct
7 Correct 25 ms 360 KB Output is correct
8 Correct 142 ms 404 KB Output is correct
9 Correct 169 ms 384 KB Output is correct
10 Correct 178 ms 396 KB Output is correct
11 Correct 182 ms 376 KB Output is correct
12 Correct 174 ms 376 KB Output is correct
13 Correct 187 ms 476 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 3 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 256 KB Output is correct
19 Correct 6 ms 384 KB Output is correct
20 Correct 22 ms 384 KB Output is correct
21 Correct 161 ms 384 KB Output is correct
22 Correct 167 ms 396 KB Output is correct
23 Correct 182 ms 384 KB Output is correct
24 Correct 221 ms 504 KB Output is correct
25 Correct 137 ms 504 KB Output is correct
26 Correct 159 ms 360 KB Output is correct
27 Correct 3 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 3 ms 384 KB Output is correct
30 Correct 75 ms 256 KB Output is correct
31 Correct 174 ms 584 KB Output is correct
32 Correct 143 ms 464 KB Output is correct
33 Correct 176 ms 376 KB Output is correct
34 Correct 146 ms 256 KB Output is correct
35 Correct 156 ms 392 KB Output is correct
36 Correct 197 ms 256 KB Output is correct
37 Correct 3 ms 640 KB Output is correct
38 Correct 3 ms 640 KB Output is correct
39 Correct 4 ms 640 KB Output is correct
40 Correct 6 ms 768 KB Output is correct
41 Correct 11 ms 768 KB Output is correct
42 Correct 5 ms 768 KB Output is correct
43 Correct 2 ms 640 KB Output is correct
44 Correct 6 ms 768 KB Output is correct
45 Correct 5 ms 768 KB Output is correct
46 Correct 5 ms 640 KB Output is correct
47 Correct 9 ms 896 KB Output is correct
48 Correct 15 ms 896 KB Output is correct
49 Correct 45 ms 1400 KB Output is correct
50 Correct 97 ms 2224 KB Output is correct
51 Correct 133 ms 2680 KB Output is correct
52 Correct 66 ms 1880 KB Output is correct
53 Correct 2 ms 640 KB Output is correct
54 Correct 151 ms 3088 KB Output is correct
55 Correct 171 ms 3192 KB Output is correct
56 Execution timed out 1078 ms 4524 KB Time limit exceeded
57 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 8 ms 384 KB Output is correct
7 Correct 25 ms 256 KB Output is correct
8 Correct 175 ms 360 KB Output is correct
9 Correct 183 ms 580 KB Output is correct
10 Correct 158 ms 256 KB Output is correct
11 Correct 168 ms 504 KB Output is correct
12 Correct 185 ms 256 KB Output is correct
13 Correct 172 ms 356 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 4 ms 256 KB Output is correct
17 Correct 67 ms 384 KB Output is correct
18 Correct 135 ms 384 KB Output is correct
19 Correct 156 ms 396 KB Output is correct
20 Correct 149 ms 384 KB Output is correct
21 Correct 146 ms 256 KB Output is correct
22 Correct 168 ms 384 KB Output is correct
23 Correct 172 ms 504 KB Output is correct
24 Correct 2 ms 640 KB Output is correct
25 Correct 2 ms 640 KB Output is correct
26 Correct 3 ms 640 KB Output is correct
27 Correct 5 ms 768 KB Output is correct
28 Correct 9 ms 768 KB Output is correct
29 Correct 5 ms 640 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 9 ms 768 KB Output is correct
32 Correct 15 ms 768 KB Output is correct
33 Correct 5 ms 768 KB Output is correct
34 Correct 8 ms 768 KB Output is correct
35 Correct 17 ms 896 KB Output is correct
36 Correct 54 ms 1400 KB Output is correct
37 Correct 100 ms 2168 KB Output is correct
38 Correct 133 ms 2680 KB Output is correct
39 Correct 67 ms 2040 KB Output is correct
40 Correct 2 ms 512 KB Output is correct
41 Correct 150 ms 2876 KB Output is correct
42 Correct 191 ms 3192 KB Output is correct
43 Execution timed out 1066 ms 4344 KB Time limit exceeded
44 Halted 0 ms 0 KB -