# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
580345 |
2022-06-21T06:15:09 Z |
반딧불(#8355) |
Uplifting Excursion (BOI22_vault) |
C++17 |
|
5000 ms |
16196 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int LIM = 505000;
const int LIM2 = LIM+LIM;
void imp(){
puts("impossible");
exit(0);
}
int n, k;
int arr[702];
int DP[2][LIM2+2];
int dq1[LIM2+2];
int dq2[LIM2+2];
int fr, sz;
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++){
fr=sz=0;
for(int j=s, p=0; j<=LIM2; j+=ri, p++){
DP[b][j] = max(DP[b][j], DP[!b][j]);
while(fr!=sz && dq2[fr] < p) fr++;
pair<int, int> np = make_pair(DP[!b][j] - p, p+arr[i]);
while(fr!=sz && dq1[sz-1] < np.first) sz--;
dq1[sz] = np.first;
dq2[sz++] = np.second;
DP[b][j] = max(DP[b][j], dq1[fr] + 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++){
fr=sz=0;
for(int j=LIM2-s, p=0; j>=0; j-=ri, p++){
DP[b][j] = max(DP[b][j], DP[!b][j]);
while(fr!=sz && dq2[fr] < p) fr++;
pair<int, int> np = make_pair(DP[!b][j] - p, p+arr[i]);
while(fr!=sz && dq1[sz-1] < np.first) sz--;
dq1[sz] = np.first;
dq2[sz++] = np.second;
DP[b][j] = max(DP[b][j], dq1[fr] + p);
}
}
}
}
if(DP[0][LIM+k] <= 0) imp();
printf("%d", DP[0][LIM+k]);
}
Compilation message
vault.cpp: In function 'int main()':
vault.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d %d", &n, &k);
| ~~~~~^~~~~~~~~~~~~~~~~
vault.cpp:23:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | for(int i=0; i<=n+n; i++) scanf("%d", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
16084 KB |
Output is correct |
2 |
Correct |
73 ms |
16012 KB |
Output is correct |
3 |
Correct |
29 ms |
16012 KB |
Output is correct |
4 |
Correct |
370 ms |
16196 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
4145 ms |
16052 KB |
Output is correct |
7 |
Correct |
3962 ms |
16092 KB |
Output is correct |
8 |
Correct |
3684 ms |
16092 KB |
Output is correct |
9 |
Correct |
3904 ms |
16128 KB |
Output is correct |
10 |
Correct |
4509 ms |
16092 KB |
Output is correct |
11 |
Correct |
3421 ms |
16092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
16084 KB |
Output is correct |
2 |
Correct |
73 ms |
16012 KB |
Output is correct |
3 |
Correct |
29 ms |
16012 KB |
Output is correct |
4 |
Correct |
370 ms |
16196 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
4145 ms |
16052 KB |
Output is correct |
7 |
Correct |
3962 ms |
16092 KB |
Output is correct |
8 |
Correct |
3684 ms |
16092 KB |
Output is correct |
9 |
Correct |
3904 ms |
16128 KB |
Output is correct |
10 |
Correct |
4509 ms |
16092 KB |
Output is correct |
11 |
Correct |
3421 ms |
16092 KB |
Output is correct |
12 |
Correct |
69 ms |
16096 KB |
Output is correct |
13 |
Correct |
104 ms |
16092 KB |
Output is correct |
14 |
Correct |
31 ms |
16084 KB |
Output is correct |
15 |
Correct |
395 ms |
16132 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
4067 ms |
16048 KB |
Output is correct |
18 |
Correct |
3966 ms |
16088 KB |
Output is correct |
19 |
Correct |
3862 ms |
16112 KB |
Output is correct |
20 |
Correct |
4438 ms |
16088 KB |
Output is correct |
21 |
Correct |
4240 ms |
16092 KB |
Output is correct |
22 |
Correct |
4269 ms |
16088 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Execution timed out |
5028 ms |
16064 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
406 ms |
16092 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 |
406 ms |
16092 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 |
406 ms |
16092 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 |
47 ms |
16084 KB |
Output is correct |
2 |
Correct |
73 ms |
16012 KB |
Output is correct |
3 |
Correct |
29 ms |
16012 KB |
Output is correct |
4 |
Correct |
370 ms |
16196 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
4145 ms |
16052 KB |
Output is correct |
7 |
Correct |
3962 ms |
16092 KB |
Output is correct |
8 |
Correct |
3684 ms |
16092 KB |
Output is correct |
9 |
Correct |
3904 ms |
16128 KB |
Output is correct |
10 |
Correct |
4509 ms |
16092 KB |
Output is correct |
11 |
Correct |
3421 ms |
16092 KB |
Output is correct |
12 |
Correct |
406 ms |
16092 KB |
Output is correct |
13 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
406 ms |
16092 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 |
47 ms |
16084 KB |
Output is correct |
2 |
Correct |
73 ms |
16012 KB |
Output is correct |
3 |
Correct |
29 ms |
16012 KB |
Output is correct |
4 |
Correct |
370 ms |
16196 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
4145 ms |
16052 KB |
Output is correct |
7 |
Correct |
3962 ms |
16092 KB |
Output is correct |
8 |
Correct |
3684 ms |
16092 KB |
Output is correct |
9 |
Correct |
3904 ms |
16128 KB |
Output is correct |
10 |
Correct |
4509 ms |
16092 KB |
Output is correct |
11 |
Correct |
3421 ms |
16092 KB |
Output is correct |
12 |
Correct |
69 ms |
16096 KB |
Output is correct |
13 |
Correct |
104 ms |
16092 KB |
Output is correct |
14 |
Correct |
31 ms |
16084 KB |
Output is correct |
15 |
Correct |
395 ms |
16132 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
4067 ms |
16048 KB |
Output is correct |
18 |
Correct |
3966 ms |
16088 KB |
Output is correct |
19 |
Correct |
3862 ms |
16112 KB |
Output is correct |
20 |
Correct |
4438 ms |
16088 KB |
Output is correct |
21 |
Correct |
4240 ms |
16092 KB |
Output is correct |
22 |
Correct |
4269 ms |
16088 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Execution timed out |
5028 ms |
16064 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
406 ms |
16092 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 |
47 ms |
16084 KB |
Output is correct |
2 |
Correct |
73 ms |
16012 KB |
Output is correct |
3 |
Correct |
29 ms |
16012 KB |
Output is correct |
4 |
Correct |
370 ms |
16196 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
4145 ms |
16052 KB |
Output is correct |
7 |
Correct |
3962 ms |
16092 KB |
Output is correct |
8 |
Correct |
3684 ms |
16092 KB |
Output is correct |
9 |
Correct |
3904 ms |
16128 KB |
Output is correct |
10 |
Correct |
4509 ms |
16092 KB |
Output is correct |
11 |
Correct |
3421 ms |
16092 KB |
Output is correct |
12 |
Correct |
69 ms |
16096 KB |
Output is correct |
13 |
Correct |
104 ms |
16092 KB |
Output is correct |
14 |
Correct |
31 ms |
16084 KB |
Output is correct |
15 |
Correct |
395 ms |
16132 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
4067 ms |
16048 KB |
Output is correct |
18 |
Correct |
3966 ms |
16088 KB |
Output is correct |
19 |
Correct |
3862 ms |
16112 KB |
Output is correct |
20 |
Correct |
4438 ms |
16088 KB |
Output is correct |
21 |
Correct |
4240 ms |
16092 KB |
Output is correct |
22 |
Correct |
4269 ms |
16088 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Execution timed out |
5028 ms |
16064 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |