답안 #251535

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
251535 2020-07-21T18:12:45 Z MrRobot_28 Lutrija (COCI19_lutrija) C++17
0 / 70
347 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);
		}
	}
	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:67:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < v.size(); i++)
                 ~~^~~~~~~~~~
lutrija.cpp:81:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < ans.size(); i++)
                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 318 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 312 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 347 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 251 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -