Submission #347186

# Submission time Handle Problem Language Result Execution time Memory
347186 2021-01-12T08:44:09 Z Nursik Lutrija (COCI19_lutrija) C++14
35 / 70
689 ms 492 KB
#include <bits/stdc++.h>
 
#define f first
#define s second
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end() 
#define ld long double
 
using namespace std; 
 
void data() {
	#ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif	
} 
void win()
{	
	ios_base::sync_with_stdio(0),
	cin.tie(0),cout.tie(0);
}
 
int block = 400;
const ld eps = 1e-6; 
 
const int N = 1e6 + 500;
const int mod = 1e9 + 7;
 
const ll hh = 100010683;
const ll hh2 = 150005819;
 
ll a, b, pos, pos2;
bool check(ll x)
{
	for (int j = 2; j <= sqrt(x); j++)
	{
		if (x % j == 0)
			return 0;
	}
	return 1;
}
bool got, was[200];
vector<int> g[200];
int par[200];
void dfs(int v)
{
//	cout << v << '\n';
	if (v == pos)
		got = 1;
	was[v] = 1;
	for (int i = 0; i < g[v].size(); i++)
	{
		int to = g[v][i];
		if (was[to] == 0)
		{
			dfs(to), par[to] = v;
		}
	}
}
int main()
{
	data();              
	win();
	cin >> a >> b;
	vector<ll> v;
	map<ll, bool> was;
	for (ll i = a - 2; i <= a + 2; i++)
	{
		if (check(i) && was[i] == 0 && i > 1)
			v.pb(i), was[i] = 1;		
	}	
	for (ll i = b - 2; i <= b + 2; i++)
	{
		if (check(i) && was[i] == 0 && i > 1)
			v.pb(i), was[i] = 1;;
	}
	if (was[2] == 0)
		v.pb(2);
	sort(all(v));
	pos = -1, pos2 = 1000;;
	for (int i = 0; i < v.size(); i++)
	{
		for (int j = 0; j < v.size(); j++)
		{
			ll k = abs(v[i] - v[j]);
			if (check(k))
				g[i].pb(j);
		}
	}
	for (int i = 0; i < v.size(); i++)
	{
		if (v[i] == b)
			pos = i;
		if (v[i] == a)
			pos2 = i;
	}
	par[pos2] = -1;
	dfs(pos2);
	if (got)
	{
		vector<int> ans;
		b = pos;
		while (par[b] != -1)
		{
			ans.pb(v[b]), b = par[b];
		}	
		ans.pb(v[b]);
		reverse(all(ans));
		cout << ans.size() << '\n';
		for (int i = 0; i < ans.size(); i++)
		{
			cout << ans[i] << " ";
		}
		return 0;
	}
	cout << -1;
}

Compilation message

lutrija.cpp: In function 'void dfs(int)':
lutrija.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for (int i = 0; i < g[v].size(); i++)
      |                  ~~^~~~~~~~~~~~~
lutrija.cpp: In function 'int main()':
lutrija.cpp:82:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |  for (int i = 0; i < v.size(); i++)
      |                  ~~^~~~~~~~~~
lutrija.cpp:84:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |   for (int j = 0; j < v.size(); j++)
      |                   ~~^~~~~~~~~~
lutrija.cpp:91:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |  for (int i = 0; i < v.size(); i++)
      |                  ~~^~~~~~~~~~
lutrija.cpp:111:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |   for (int i = 0; i < ans.size(); i++)
      |                   ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 633 ms 396 KB Integer parameter [name=arr[4]] equals to -2039078211, violates the range [1, 1000000000000000]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 617 ms 492 KB Integer parameter [name=arr[1]] equals to -2145466189, violates the range [1, 1000000000000000]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 689 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 503 ms 492 KB Integer parameter [name=arr[4]] equals to -2070243847, violates the range [1, 1000000000000000]
2 Halted 0 ms 0 KB -