Submission #580340

# Submission time Handle Problem Language Result Execution time Memory
580340 2022-06-21T06:05:13 Z 반딧불(#8355) Uplifting Excursion (BOI22_vault) C++17
0 / 100
5000 ms 9684 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int LIM = 600000;
const int LIM2 = LIM+LIM;

void imp(){
    puts("impossible");
    exit(0);
}

int n, k;
int arr[702];
int DP[2][1200002];

int main(){
    scanf("%d %d", &n, &k);
    for(int i=0; i<=n+n; i++) scanf("%d", &arr[i]);
    if(k<=-LIM || k>=LIM) imp();
    for(int i=0; i<=LIM2; i++) DP[0][i] = DP[1][i] = -1e9;
    DP[1][LIM] = 0;

    for(int i=0; i<=n+n; i++){ /// ����ġ: i+n
        int b = i%2;
        if(i>n){ /// ���� ����ġ
            int ri = i-n;
            for(int s=0; s<i+ri; s++){
                deque<pair<int, int> > dq; /// (��, �Ѱ�)
                for(int j=s, p=0; j<=LIM2; j+=ri, p++){
                    DP[b][j] = max(DP[b][j], DP[!b][j]);
                    while(!dq.empty() && dq.front().second < p) dq.pop_front();
                    pair<int, int> np = make_pair(DP[!b][j] - p, p+arr[i]);
                    while(!dq.empty() && dq.back().first < np.first) dq.pop_back();
                    dq.push_back(np);
                    DP[b][j] = max(DP[b][j], dq.front().first + p);
                }
            }
        }
        else if(i==n){
            for(int j=0; j<=LIM2; j++) DP[b][j] = max(DP[b][j], DP[!b][j]) + arr[i];
        }
        else{
            int ri = n-i;
            for(int s=0; s<i+ri; s++){
                deque<pair<int, int> > dq; /// (��, �Ѱ�)
                for(int j=LIM2-s, p=0; j>=0; j-=ri, p++){
                    DP[b][j] = max(DP[b][j], DP[!b][j]);
                    while(!dq.empty() && dq.front().second < p) dq.pop_front();
                    pair<int, int> np = make_pair(DP[!b][j] - p, p+arr[i]);
                    while(!dq.empty() && dq.back().first < np.first) dq.pop_back();
                    dq.push_back(np);
                    DP[b][j] = max(DP[b][j], dq.front().first + p);
                }
            }
        }
    }

    if(DP[0][LIM+k] <= 0) imp();
    printf("%d", DP[0][LIM+k]);
}

Compilation message

vault.cpp: In function 'int main()':
vault.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
vault.cpp:20:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     for(int i=0; i<=n+n; i++) scanf("%d", &arr[i]);
      |                               ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 134 ms 9684 KB Output is correct
2 Correct 294 ms 9684 KB Output is correct
3 Correct 60 ms 9684 KB Output is correct
4 Correct 1156 ms 9684 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Execution timed out 5072 ms 9684 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 134 ms 9684 KB Output is correct
2 Correct 294 ms 9684 KB Output is correct
3 Correct 60 ms 9684 KB Output is correct
4 Correct 1156 ms 9684 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Execution timed out 5072 ms 9684 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1148 ms 9684 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1148 ms 9684 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1148 ms 9684 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 134 ms 9684 KB Output is correct
2 Correct 294 ms 9684 KB Output is correct
3 Correct 60 ms 9684 KB Output is correct
4 Correct 1156 ms 9684 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Execution timed out 5072 ms 9684 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1148 ms 9684 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 134 ms 9684 KB Output is correct
2 Correct 294 ms 9684 KB Output is correct
3 Correct 60 ms 9684 KB Output is correct
4 Correct 1156 ms 9684 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Execution timed out 5072 ms 9684 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1148 ms 9684 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 134 ms 9684 KB Output is correct
2 Correct 294 ms 9684 KB Output is correct
3 Correct 60 ms 9684 KB Output is correct
4 Correct 1156 ms 9684 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Execution timed out 5072 ms 9684 KB Time limit exceeded
7 Halted 0 ms 0 KB -