Submission #342309

#TimeUsernameProblemLanguageResultExecution timeMemory
342309VodkaInTheJarSažetak (COCI17_sazetak)C++14
64 / 160
306 ms10896 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define endl '\n'

using namespace std;

const int maxn = 5e6 + 3; 
const int maxm = 13;

int n, m; 
int k[maxm];
void read()
{
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
	cin >> k[i];
}

bool dp[maxn];
void solve()
{
	dp[0] = true;
	for (int i = 1; i < n; i++)
	for (int j = 1; j <= m; j++)
	if (k[j] <= i && dp[i-k[j]] && i % k[j] == 0)
	{
		dp[i] = true;
		break;
	}
	
	dp[n] = true; 
	int ans = 0; 
	for (int i = 0; i <= n-1; i++)
	if (dp[i] && dp[i+1])
	ans++;
	
	cout << ans << endl; 
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	read();
	solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...