Submission #251536

# Submission time Handle Problem Language Result Execution time Memory
251536 2020-07-21T18:14:46 Z MrRobot_28 Lutrija (COCI19_lutrija) C++17
70 / 70
514 ms 384 KB
#include<bits/stdc++.h>
 
using namespace std;
#define int long long
const int N = 10;
vector <bool> used(N);
vector <int> v, tmp, ans;
int a, b;
bool prost(int x)
{
	if(x < 2)
	{
		return 0;
	}
	for(int j = 2; j * j <= x; j++)
	{
		if(x % j == 0)
		{
			return 0;
		}
	}
	return 1;
}
void dfs(int x)
{
	used[x] = true;
	tmp.push_back(v[x]);
	if(v[x] == b){
		if(ans.size() == 0 || ans.size() > tmp.size())
		{
			ans = tmp;
		}
		tmp.pop_back();
		return;
	}
	for(int i = 0; i < v.size(); i++)
	{
		if(!used[i] && prost(abs(v[x] - v[i])))
		{
			dfs(i);
			used[i] = 0;
		}
	}
	tmp.pop_back();
}
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> a >> b;
	for(int i = a - 2; i <= a + 2; i++)
	{
		if(prost(i))
		{
			v.push_back(i);
		}
	}
	for(int i = b - 2; i <= b + 2; i++)
	{
		if(prost(i))
		{
			v.push_back(i);
		}
	}
	v.push_back(2);
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	for(int i = 0; i < v.size(); i++)
	{
		if(v[i] == a)
		{
			dfs(i);
		}
	}
	if(ans.size() == 0)
	{
		cout << -1;
	}
	else
	{
		cout << ans.size() << "\n";
		for(int i = 0; i < ans.size(); i++)
		{
			cout << ans[i] << " ";
		}
	}
	return 0;
}

Compilation message

lutrija.cpp: In function 'void dfs(long long int)':
lutrija.cpp:36:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.size(); i++)
                 ~~^~~~~~~~~~
lutrija.cpp: In function 'int main()':
lutrija.cpp:68:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.size(); i++)
                 ~~^~~~~~~~~~
lutrija.cpp:82:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < ans.size(); i++)
                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 477 ms 384 KB Output is correct
2 Correct 232 ms 384 KB Output is correct
3 Correct 384 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 461 ms 376 KB Output is correct
2 Correct 202 ms 384 KB Output is correct
3 Correct 275 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 514 ms 384 KB Output is correct
2 Correct 250 ms 384 KB Output is correct
3 Correct 253 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 376 ms 376 KB Output is correct
2 Correct 172 ms 384 KB Output is correct
3 Correct 91 ms 384 KB Output is correct