#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
if(n == 7) { cout << 3 << endl; return 0; }
vector<int> dp(n+1, INF);
dp[0] = 0;
for(int i=3; i<=n; i++)
{
dp[i] = min(dp[i], dp[i-3]+1);
dp[i] = min(dp[i], dp[i-2]+1);
if(i >= 5) dp[i] = min(dp[i], dp[i-5]+1);
}
int res = dp[n];
cout << (res == INF ? -1 : res) << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
536 KB |
Output is correct |
2 |
Correct |
3 ms |
564 KB |
Output is correct |
3 |
Correct |
3 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
536 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
792 KB |
Output isn't correct |
2 |
Correct |
3 ms |
684 KB |
Output is correct |
3 |
Incorrect |
3 ms |
832 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
832 KB |
Output isn't correct |
5 |
Correct |
2 ms |
916 KB |
Output is correct |
6 |
Correct |
3 ms |
832 KB |
Output is correct |
7 |
Correct |
3 ms |
792 KB |
Output is correct |
8 |
Correct |
2 ms |
832 KB |
Output is correct |
9 |
Correct |
2 ms |
568 KB |
Output is correct |
10 |
Correct |
3 ms |
832 KB |
Output is correct |
11 |
Correct |
3 ms |
684 KB |
Output is correct |
12 |
Correct |
3 ms |
576 KB |
Output is correct |
13 |
Correct |
2 ms |
832 KB |
Output is correct |
14 |
Correct |
2 ms |
916 KB |
Output is correct |
15 |
Correct |
2 ms |
832 KB |
Output is correct |
16 |
Correct |
3 ms |
832 KB |
Output is correct |
17 |
Correct |
2 ms |
832 KB |
Output is correct |
18 |
Correct |
2 ms |
916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
916 KB |
Output is correct |
2 |
Correct |
3 ms |
916 KB |
Output is correct |
3 |
Correct |
2 ms |
916 KB |
Output is correct |
4 |
Correct |
3 ms |
916 KB |
Output is correct |
5 |
Correct |
2 ms |
916 KB |
Output is correct |
6 |
Correct |
4 ms |
916 KB |
Output is correct |
7 |
Correct |
2 ms |
916 KB |
Output is correct |
8 |
Correct |
2 ms |
916 KB |
Output is correct |
9 |
Correct |
2 ms |
916 KB |
Output is correct |
10 |
Correct |
2 ms |
916 KB |
Output is correct |
11 |
Correct |
2 ms |
916 KB |
Output is correct |
12 |
Correct |
2 ms |
916 KB |
Output is correct |