답안 #624018

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
624018 2022-08-07T06:48:40 Z jiahng Uplifting Excursion (BOI22_vault) C++14
0 / 100
78 ms 45764 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define int ll
typedef pair<int,int> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 611
#define INF (ll)(1e18+10)
#define MOD 998244353
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
typedef pair <pi,pi> pipi;

int dp[maxn][maxn][maxn];
int A[maxn], sm = 0;
int M,L;
int32_t main(){
    fast;
    cin >> M >> L;
    FOR(i,0,2*M) cin >> A[i];
    vector <pii> v;
    int ans = 0;
    FOR(i,M,2*M) if (sm < L){
        int x = INF;
        if (i != M){
            x = (L - sm) / (i - M);
        }
        x = min(x, A[i]);
        sm += x * (i-M); 
        A[i] -= x;
        v.pb(pii(pi(-(i-M), x), -1));
        ans += x;
        assert(sm <= L);
        if (A[i] > 0 && sm < L){
            sm += i - M; A[i]--; ans++;
            v.pb(pii(pi(-(i-M),1),-1));
            assert(sm <= L + M);
            break;
        }
    }
    //cout << sm << ' ' << ans << '\n';
    //FOR(i,0,2*M) cout << A[i] << ' ';
    //cout << '\n';
    if (sm < L){
        cout << "impossible"; return 0;
    }
    //assert(sm <= L + M);

    FOR(i,0,2*M) v.pb(pii(pi(i-M, A[i]), 1));

    vector <pii> pos, neg;
    aFOR(i, v) if (i.f.s > 0){
        if (i.f.f >= 0) pos.pb(i);
        else neg.pb(i);
    }

    FOR(i,0,2*M) dp[i][0][0] = -INF;
    dp[M][0][0] = 0;
        
    FOR(j,0,pos.size()) FOR(k,0,neg.size()) if (j > 0 || k > 0){
        FOR(i,0,2*M){
           dp[i][j][k] = -INF;
           if (j > 0){
                FOR(x,0,min(pos[j-1].f.s, 2*M)) if (0 <= i + x * pos[j-1].f.f && i + x * pos[j-1].f.f <= 2*M){
                    dp[i][j][k] = max(dp[i][j][k], dp[i+x*pos[j-1].f.f][j-1][k] + x * pos[j-1].s);
                }
           }
           if (k > 0){
                FOR(x,0,min(neg[k-1].f.s, 2*M)) if (0 <= i + x * neg[k-1].f.f && i + x * neg[k-1].f.f <= 2*M){
                    dp[i][j][k] = max(dp[i][j][k], dp[i+x*neg[k-1].f.f][j][k-1] + x * neg[k-1].s);
                }
           }
        }
    }
    ans += dp[sm - L + M][pos.size()][neg.size()];
    if (ans < 0) cout << "impossible";
    else cout << ans;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Runtime error 78 ms 45764 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Runtime error 78 ms 45764 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 2 ms 1876 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 5 ms 5588 KB Output is correct
5 Correct 3 ms 2052 KB Output is correct
6 Correct 4 ms 7892 KB Output is correct
7 Incorrect 1 ms 1492 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 2 ms 1876 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 5 ms 5588 KB Output is correct
5 Correct 3 ms 2052 KB Output is correct
6 Correct 4 ms 7892 KB Output is correct
7 Incorrect 1 ms 1492 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 2 ms 1876 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 5 ms 5588 KB Output is correct
5 Correct 3 ms 2052 KB Output is correct
6 Correct 4 ms 7892 KB Output is correct
7 Incorrect 1 ms 1492 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Runtime error 78 ms 45764 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 2 ms 1876 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 5 ms 5588 KB Output is correct
5 Correct 3 ms 2052 KB Output is correct
6 Correct 4 ms 7892 KB Output is correct
7 Incorrect 1 ms 1492 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Runtime error 78 ms 45764 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1236 KB Output is correct
2 Correct 2 ms 1876 KB Output is correct
3 Correct 1 ms 724 KB Output is correct
4 Correct 5 ms 5588 KB Output is correct
5 Correct 3 ms 2052 KB Output is correct
6 Correct 4 ms 7892 KB Output is correct
7 Incorrect 1 ms 1492 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 1236 KB Output is correct
5 Runtime error 78 ms 45764 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -