답안 #297679

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
297679 2020-09-11T18:05:12 Z AaronNaidu Bali Sculptures (APIO15_sculpture) C++14
0 / 100
1 ms 512 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll n, a, b;
ll y[2001];
ll prefSums[2001];
ll minAns = 1000000000000;
bool poss[101][2001][101];
bool found[101][2001][101];

bool getDP(int num, int sum, int regions) {
    if (found[num][sum][regions])
    {
        return poss[num][sum][regions];
    }
    if (regions == 0 or num == n)
    {
        poss[num][sum][regions] = false;
        found[num][sum][regions] = true;
        return false;
    }
    if (regions == 1) {
        poss[num][sum][regions] = ((prefSums[n] - prefSums[num]) | sum) == sum;
        //cout << num << " " << sum << " " << regions << " returns " << poss[num][sum][regions] << "\n";
        found[num][sum][regions] = true;
        return ((prefSums[n] - prefSums[num]) | sum) == sum;
    }
    for (int i = num+1; i <= n; i++)
    {
        if (((prefSums[i] - prefSums[num]) | sum) == sum)
        {
            poss[num][sum][regions] |= getDP(i, sum, regions-1);
        }
    }
    //cout << num << " " << sum << " " << regions << " returns " << poss[num][sum][regions] << "\n";
    found[num][sum][regions] = true;
    return poss[num][sum][regions];
}

int main() {
    cin >> n >> a >> b;
    y[0] = 0;
    prefSums[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> y[i];
        prefSums[i] = prefSums[i-1] + y[i];
    }
    //cout << "Pref sums: ";
    for (int i = 0; i <= n; i++)
    {
        //cout << prefSums[i] << " " << "\n";
    }
    
    for (int i = 1; i <= 1000000; i++)
    {
        for (int j = a; j <= b; j++)
        {
            if (getDP(0, i, j))
            {
                cout << i << "\n";
                return 0;
            }
        }
    }
    //getDP(0, 4, 2);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Incorrect 0 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 0 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 0 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -