#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back
const int M=5001;
const ll inf=1e9+10;
ll n,a,b,c;
string s;
bool vis[M][M];
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
cin>>n>>s>>a>>b>>c;
priority_queue<pair<ll,pii>,vector<pair<ll,pii>>,greater<pair<ll,pii>>>q;
q.push({0,{0,0}});
while(1){
pair<ll,pii>p=q.top();
q.pop();
if(p.S.F>n||vis[p.S.F][p.S.S])
continue;
vis[p.S.F][p.S.S]=1;
if(p.S.F==n){
cout<<p.F;
return 0;
}
q.push({p.F+a,{p.S.F+1ll,p.S.S}});
q.push({p.F+b,{0ll,p.S.F}});
q.push({p.F+c,{p.S.F+p.S.S,p.S.S}});
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
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 |
363 ms |
20220 KB |
Output is correct |
4 |
Correct |
193 ms |
15284 KB |
Output is correct |
5 |
Correct |
681 ms |
58536 KB |
Output is correct |
6 |
Correct |
7 ms |
8656 KB |
Output is correct |
7 |
Correct |
596 ms |
108624 KB |
Output is correct |
8 |
Correct |
9 ms |
8656 KB |
Output is correct |
9 |
Correct |
5 ms |
10524 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
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 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |