답안 #993490

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
993490 2024-06-05T19:53:55 Z MarwenElarbi Uplifting Excursion (BOI22_vault) C++17
5 / 100
5000 ms 23240 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#define fi first
#define se second
#define ll long long
#define pb push_back
#define int long long 
const int nax=205;
vector<pair<int,int>> objects;
void add(int x , int i)
{
    while(x)
    {
        int msb = 31 - __builtin_clz(x);
        if(x == (1<<(msb + 1)) - 1)
        {

            for(int j = 0 ; j <= msb ; j++)
            {
                objects.pb({(1<<j) * i, (1<<j)});
            }
            break;
        }
        int cur=0;
        for(int j = 0 ; j < msb ; j++)
        {
            cur+=(1<<j);
            objects.pb({(1<<j) * i , (1<<j)});
        }
        x-=cur;
    }
}
const int INF = 1e18;
signed main(){
    int m , L;
    cin>>m>>L;
    unordered_map<int, int> dp;
    int ans = 0;
    int MX=0;
    int MN=1e9;
    int cur=0;
    for(int i = -m ; i <= m ; i++)
    {
        int x;
        cin>>x;
        cur+=x*i;
        MN=min(MN,cur);
        MX=max(MX,cur);
        if(i == 0){
            ans=x;
        }else add(x , i);
    }
    MX=max(abs(MN),MX);
    MX++;
    for(int i = -MX + 1 ; i <= MX - 1; i++)
    {
        dp[i] = -INF;
    }
    dp[0] = ans;
    sort(objects.begin(),objects.end());
    for(auto c : objects){
        if(c.fi > 0){
            for(int j = MX - 1 ; j >= -MX + 1 ; j--)
            {
                if(j - c.fi >= -MX + 1)
                    dp[j] = max(dp[j] , dp[j - c.fi] + c.se);
            }
        }else 
        {
            for(int j = -MX + 1 ; j <= MX - 1 ; j++)
            {
                if(j - c.fi <= MX - 1)
                {
                    dp[j] = max(dp[j] , dp[j - c.fi] + c.se);
                }
            }
        }
    }
    if(L>=MX||L<=-MX) cout <<"impossible"<<endl;
    else if(dp[L]<=0) cout <<"impossible"<<endl;
    else cout << dp[L]<<endl;
}
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
5 Correct 868 ms 3248 KB Output is correct
6 Correct 610 ms 3180 KB Output is correct
7 Correct 118 ms 1464 KB Output is correct
8 Correct 777 ms 2924 KB Output is correct
9 Correct 2271 ms 5596 KB Output is correct
10 Correct 5 ms 604 KB Output is correct
11 Correct 4 ms 604 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 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 868 ms 3248 KB Output is correct
6 Correct 610 ms 3180 KB Output is correct
7 Correct 118 ms 1464 KB Output is correct
8 Correct 777 ms 2924 KB Output is correct
9 Correct 2271 ms 5596 KB Output is correct
10 Correct 5 ms 604 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 1 ms 344 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 844 ms 3244 KB Output is correct
17 Correct 603 ms 3176 KB Output is correct
18 Correct 114 ms 1716 KB Output is correct
19 Correct 548 ms 2924 KB Output is correct
20 Correct 1674 ms 5588 KB Output is correct
21 Correct 4 ms 604 KB Output is correct
22 Correct 4 ms 768 KB Output is correct
23 Execution timed out 5091 ms 23240 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Execution timed out 5088 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Execution timed out 5088 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Execution timed out 5088 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
5 Correct 868 ms 3248 KB Output is correct
6 Correct 610 ms 3180 KB Output is correct
7 Correct 118 ms 1464 KB Output is correct
8 Correct 777 ms 2924 KB Output is correct
9 Correct 2271 ms 5596 KB Output is correct
10 Correct 5 ms 604 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Execution timed out 5088 ms 348 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Execution timed out 5088 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
5 Correct 868 ms 3248 KB Output is correct
6 Correct 610 ms 3180 KB Output is correct
7 Correct 118 ms 1464 KB Output is correct
8 Correct 777 ms 2924 KB Output is correct
9 Correct 2271 ms 5596 KB Output is correct
10 Correct 5 ms 604 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 1 ms 344 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 844 ms 3244 KB Output is correct
17 Correct 603 ms 3176 KB Output is correct
18 Correct 114 ms 1716 KB Output is correct
19 Correct 548 ms 2924 KB Output is correct
20 Correct 1674 ms 5588 KB Output is correct
21 Correct 4 ms 604 KB Output is correct
22 Correct 4 ms 768 KB Output is correct
23 Execution timed out 5091 ms 23240 KB Time limit exceeded
24 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Execution timed out 5088 ms 348 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 1 ms 348 KB Output is correct
5 Correct 868 ms 3248 KB Output is correct
6 Correct 610 ms 3180 KB Output is correct
7 Correct 118 ms 1464 KB Output is correct
8 Correct 777 ms 2924 KB Output is correct
9 Correct 2271 ms 5596 KB Output is correct
10 Correct 5 ms 604 KB Output is correct
11 Correct 4 ms 604 KB Output is correct
12 Correct 1 ms 344 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 844 ms 3244 KB Output is correct
17 Correct 603 ms 3176 KB Output is correct
18 Correct 114 ms 1716 KB Output is correct
19 Correct 548 ms 2924 KB Output is correct
20 Correct 1674 ms 5588 KB Output is correct
21 Correct 4 ms 604 KB Output is correct
22 Correct 4 ms 768 KB Output is correct
23 Execution timed out 5091 ms 23240 KB Time limit exceeded
24 Halted 0 ms 0 KB -