답안 #39342

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
39342 2018-01-11T20:47:19 Z ztrong Bali Sculptures (APIO15_sculpture) C++14
0 / 100
0 ms 2200 KB
#include <bits/stdc++.h>
#define llint long long
#define fi first
#define se second
#define BIT(x, i) ((x>>i)&1ll)
#define MASK(i) (1ll<<i)
#define db(x) cout << #x << " = " << x << endl;
using namespace std;

void openFile() {
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
#ifdef Tr___
    freopen("test.inp", "r", stdin);
    freopen("test.out", "w", stdout);
#else
    //freopen("tname.inp", "r", stdin);
    //freopen("tname.out", "w", stdout);
#endif
}
template <typename T>
inline void read(T &ret){
	register char c = getchar(); bool neg = false; ret = 0;
	while (c < '0' || c > '9'){ if (c == '-') neg = true; c = getchar(); }
	while (c >= '0' && c <= '9'){ ret = (ret << 1) + (ret << 3) + c - '0'; 
        c = getchar(); }
	if (neg) ret = -ret;
}

template <typename T>
void write(T x){
	if (x < 0){ putchar('-'); x = -x; }
	if (x >= 10) write(x / 10); putchar(x % 10 + 48);
}

const int maxn = 2e3 + 5;
const int maxm = 1e2 + 5;
const llint inf = 1e9 + 7;

int N, A, B;
int a[maxn];
llint s[maxn];

void enter() {
    cin >> N >> A >> B;
    for (int i = 1; i <= N; ++i) {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
    }
}

void solve1() {
    llint ans = 0;
    llint state = 0;
    bool f[maxm][maxm];
    for (int p = 50; p >= 0; --p) {
        state |= MASK(p);
        fill_n(&f[0][0], maxm * maxm, false);
        f[0][0] = true;
        for (int i = 1; i <= N; ++i) {
            for (int j = 0; j < i; ++j) {
                for (int k = 0; k < i; ++k) {
                    if ((state & (s[i] - s[j])) == 0) f[i][j] |= f[k][j - 1];
                }
            }
        }

        bool ok = false;
        for (int i = A; i <= B; ++i) {
            ok |= f[N][i];
        }
        if (!ok) {
            state ^= MASK(p);
            ans = ans + MASK(p);
        }
    }
    cout << ans << endl;
}

void solve2() {
    llint ans = 0;
    llint state = 0;
    int f[maxn];

    for (int p = 50; p >= 0; --p) {
        state |= MASK(p);
        fill_n(f, maxn, inf);
        f[0] = 0;
        for (int i = 1; i <= N; ++i) {
            for (int j = 0; j < i; ++j) {
                if (((s[i] - s[j]) & state) == 0) {
                    f[i] = min(f[i], f[j] + 1);
                }
            }
        }
        if (f[N] > B) {
            state ^= MASK(p);
            ans = ans + MASK(p);
        }
    }
    cout << ans << endl;
}

void solve() {
    if (N <= 100) {
        solve1();
    }
    else {
        solve2();
    }
}

int main() {
    openFile();
    enter();
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2200 KB Output is correct
2 Incorrect 0 ms 2200 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2200 KB Output is correct
2 Incorrect 0 ms 2200 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2200 KB Output is correct
2 Incorrect 0 ms 2200 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2200 KB Output is correct
2 Incorrect 0 ms 2200 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2200 KB Output is correct
2 Incorrect 0 ms 2200 KB Output isn't correct
3 Halted 0 ms 0 KB -