#include <bits/stdc++.h>
#define z exit(0)
typedef long long ll;
using namespace std;
const int N = 2555;
const ll inf = 1e18;
char s[N];
ll dp[N*4][N*4];
int A, B, C, n, vis[N<<1][N<<1];
signed main(){
scanf("%d %s %d %d %d", &n, s, &A, &B, &C);
for(int i = 0; i<=n; ++i) fill(dp[i], dp[i]+4*n+1, inf);
using T = tuple<ll,int,int>;
priority_queue<T, vector<T>, greater<T>> pq;
pq.emplace(dp[0][0] = 0, 0, 0);
while(!pq.empty()){
ll dis; int i, j; tie(dis, i, j) = pq.top(); pq.pop();
if(vis[i][j]) continue; vis[i][j] = 1;
if(dp[i][j] >= inf) continue;
if(i+1 <= 4*n && dp[i+1][j] > dp[i][j] + A) pq.emplace(dp[i+1][j] = dp[i][j] + A, i+1, j);
if(i+j <= 4*n && dp[0][i+j] > dp[i][j] + B) pq.emplace(dp[0][i+j] = dp[i][j] + B, 0, i+j);
if(i+j <= 4*n && dp[i+j][j] > dp[i][j] + C) pq.emplace(dp[i+j][j] = dp[i][j] + C, i+j, j);
}
printf("%lld", *min_element(dp[n], dp[n]+4*n+1));
}
Compilation message
copypaste3.cpp: In function 'int main()':
copypaste3.cpp:18:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
18 | if(vis[i][j]) continue; vis[i][j] = 1;
| ^~
copypaste3.cpp:18:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
18 | if(vis[i][j]) continue; vis[i][j] = 1;
| ^~~
copypaste3.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | scanf("%d %s %d %d %d", &n, s, &A, &B, &C);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
592 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1372 ms |
156572 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |