# TRIP2 - Editorial

**URL:** <https://discuss.codechef.com/t/trip2-editorial/36497>\
**Category:** editorial\
**Tags:** editorial, simple, taran\_1407, ltime75\
**Created:** [August 31, 2019, 4:45pm UTC](https://discuss.codechef.com/t/trip2-editorial/36497 "2019-08-31T16:45:30Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![anon90984164](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@anon90984164](https://discuss.codechef.com/u/anon90984164)\
**Post date:** [September 1, 2019, 2:37pm UTC](https://discuss.codechef.com/t/trip2-editorial/36497/42 "2019-09-01T14:37:51Z")

</div>

@aryan12

Thnakyou so very much , i was unable to find the case where it was failing .  
Thank you 😇😇😇😇😇

Thankyou so much , it got submiited , their was a error of one character , i CHANGED + TO - AND BOOM !!!

---

<div class="post-metadata">

**Author:** ![foxsgiven0](https://discuss.codechef.com/user_avatar/discuss.codechef.com/foxsgiven0/32/3653_2.png) [@foxsgiven0](https://discuss.codechef.com/u/foxsgiven0)\
**Post date:** [September 1, 2019, 2:56pm UTC](https://discuss.codechef.com/t/trip2-editorial/36497/43 "2019-09-01T14:56:39Z")

</div>

yes! Stacks size seems to the problem. Thank you for pointing out.

---

<div class="post-metadata">

**Author:** ![yash\_2711](https://discuss.codechef.com/user_avatar/discuss.codechef.com/yash_2711/32/3653_2.png) [@yash\_2711](https://discuss.codechef.com/u/yash_2711)\
**Post date:** [September 1, 2019, 3:32pm UTC](https://discuss.codechef.com/t/trip2-editorial/36497/44 "2019-09-01T15:32:21Z")

</div>

**What’s wrong ??**

[https://www.codechef.com/viewsolution/26200425](https://www.codechef.com/viewsolution/26200425)

---

<div class="post-metadata">

**Author:** ![ssjgz](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ssjgz/32/346011_2.png) [@ssjgz](https://discuss.codechef.com/u/ssjgz)\
**Post date:** [September 1, 2019, 3:38pm UTC](https://discuss.codechef.com/t/trip2-editorial/36497/45 "2019-09-01T15:38:23Z")

</div>

Thanks for actually linking your solution 🙂

It fails for the following testcase:

```auto
1
5 2
2 -1 -1 -1 -1 

```

---

<div class="post-metadata">

**Author:** ![ssjgz](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ssjgz/32/346011_2.png) [@ssjgz](https://discuss.codechef.com/u/ssjgz)\
**Post date:** [September 1, 2019, 6:21pm UTC](https://discuss.codechef.com/t/trip2-editorial/36497/47 "2019-09-01T18:21:12Z")

</div>

I get a 403 error when trying to access your solution 😕

---

<div class="post-metadata">

**Author:** ![ssjgz](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ssjgz/32/346011_2.png) [@ssjgz](https://discuss.codechef.com/u/ssjgz)\
**Post date:** [September 1, 2019, 6:35pm UTC](https://discuss.codechef.com/t/trip2-editorial/36497/49 "2019-09-01T18:35:28Z")

</div>

That is not the link to your solution XD The correct link is: [CodeChef: Practical coding for everyone](https://www.codechef.com/viewsolution/26204741)

Consider the testcase:

```auto
1
10 2
-1 -1 -1 -1 -1 2 -1 -1 -1 2 

```

---

<div class="post-metadata">

**Author:** ![sankethbk](https://discuss.codechef.com/user_avatar/discuss.codechef.com/sankethbk/32/6312_2.png) [@sankethbk](https://discuss.codechef.com/u/sankethbk)\
**Post date:** [September 1, 2019, 6:45pm UTC](https://discuss.codechef.com/t/trip2-editorial/36497/50 "2019-09-01T18:45:10Z")

</div>

Please help me i don;t know at which case it’s failing

//Chef and Trip  
#include\<bits/stdc++.h\>  
using namespace std;

typedef long long ll;

void print(int o,int t,int n)  
{  
int start;  
if (o == -1 && t == -1)  
start = 1;  
else if ( o != -1)  
{  
if (!o%2)  
start = 1;  
else  
start = 2;  
}  
else if ( t != -1)  
{  
if (!o%2)  
start = 2;  
else  
start = 2;  
}  
for (auto i = 0; i \< n; ++i)  
{  
cout\<\<start\<\<" ";  
(start == 1) ? ( start += 1):(start -= 1) ;  
}   
cout\<\<endl;  
}

int my\_find\_if(int k1,int k2 = 0)  
{

```
vector<int> v = {1,2,3};
for (auto i = v.begin(); i != v.end() ; ++i)
{
	if (*i != k1 && *i != k2)
		return *i;
}
return 0;

```

}  
int main()  
{  
int t , c;  
ll n , k;

```
cin>>t;
while (t--)
{
	cin>>n>>k;
	vector<int> v1(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>c;
		v1[i] = c;
	}

	int oneth_pos = -1;
	int twoth_pos = -1;
	bool x = 1;
	if (k == 2)
	{
		for (int it = 0 ; it < n ; ++it)
		{
			if (v1[it] == 1)
			{
				if (oneth_pos == -1)
				{
					oneth_pos = it ;
				}
				else 
				{
					if ((it - oneth_pos) & 1)
					{
						x = 0;
						break;
					}
					else
						oneth_pos = it;
				}
			}
			else if (v1[it] == 2)
			{
				if (twoth_pos == -1)
				{
					twoth_pos = it;
				}
				else 
				{
					if ((it - twoth_pos) & 1)
					{
						x = 0;
						break;
					}
					else
						twoth_pos = it;
				}
			}	
			if (oneth_pos != -1 && twoth_pos != -1)
			{
				if (abs(oneth_pos - twoth_pos)%2 != 1)
				{
					x = 0;
					break;
				}
			}		
		}
		if (!x)
		{
			cout<<"NO\n";
		}
		else
		{
			cout<<"YES\n";
			print(oneth_pos,twoth_pos,n);
		}
	}
	else
	{
		for (int i = 0; i < n; ++i)
		{
			if (v1[i] == -1)
			{
				if (i == 0)
				{
					v1[i] = my_find_if(v1[i+1]);
				}
				else if ( i < n - 1)
				{
					v1[i] = my_find_if(v1[i-1],v1[i+1]);
				}
				else
				{
					v1[i] = my_find_if(v1[i-1]);
				}
			}
		}
		cout<<"YES\n";
		for (auto i = v1.begin() ; i != v1.end() ; ++i )
		{
			cout<<*i<<" ";
		}
		cout<<endl;
	}
}

```

}

---

<div class="post-metadata">

**Author:** ![ssjgz](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ssjgz/32/346011_2.png) [@ssjgz](https://discuss.codechef.com/u/ssjgz)\
**Post date:** [September 1, 2019, 6:47pm UTC](https://discuss.codechef.com/t/trip2-editorial/36497/51 "2019-09-01T18:47:19Z")

</div>

See my post above 🙂

---

<div class="post-metadata">

**Author:** ![sankethbk](https://discuss.codechef.com/user_avatar/discuss.codechef.com/sankethbk/32/6312_2.png) [@sankethbk](https://discuss.codechef.com/u/sankethbk)\
**Post date:** [September 1, 2019, 6:51pm UTC](https://discuss.codechef.com/t/trip2-editorial/36497/52 "2019-09-01T18:51:11Z")

</div>

It’s even passing the testcases like  
4 2  
-1 -1 1 -1

please help me

---

<div class="post-metadata">

**Author:** ![sankethbk](https://discuss.codechef.com/user_avatar/discuss.codechef.com/sankethbk/32/6312_2.png) [@sankethbk](https://discuss.codechef.com/u/sankethbk)\
**Post date:** [September 1, 2019, 6:53pm UTC](https://discuss.codechef.com/t/trip2-editorial/36497/53 "2019-09-01T18:53:25Z")

</div>

Please help me bro  
i tried all the test cases that you have mentioned above , it is working fine

---

<div class="post-metadata">

**Author:** ![ssjgz](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ssjgz/32/346011_2.png) [@ssjgz](https://discuss.codechef.com/u/ssjgz)\
**Post date:** [September 1, 2019, 6:56pm UTC](https://discuss.codechef.com/t/trip2-editorial/36497/54 "2019-09-01T18:56:16Z")

</div>

> [@sankethbk](#):
>
> it is working fine

Well, no it isn’t, which is why I posted it 🙂

Your program seems to output

```auto
YES
2 1 2 1 2 1 2 1 2 1

```

for the testcase

```auto
1
10 2
-1 -1 -1 -1 -1 2 -1 -1 -1 2 

```

which is not a valid answer.

I’ll “superimpose” the input array and your output array to hopefully make things clearer 🙂

```auto
-1 -1 -1 -1 -1 2 -1 -1 -1 2 <-- The input array
 2 1 2 1 2 1 2 1 2 1 <-- Your output

```

---

<div class="post-metadata">

**Author:** ![sankethbk](https://discuss.codechef.com/user_avatar/discuss.codechef.com/sankethbk/32/6312_2.png) [@sankethbk](https://discuss.codechef.com/u/sankethbk)\
**Post date:** [September 1, 2019, 6:59pm UTC](https://discuss.codechef.com/t/trip2-editorial/36497/55 "2019-09-01T18:59:02Z")

</div>

Thank you very much bro.

---

<div class="post-metadata">

**Author:** ![ankit9437](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ankit9437/32/3417_2.png) [@ankit9437](https://discuss.codechef.com/u/ankit9437)\
**Post date:** [September 2, 2019, 5:32am UTC](https://discuss.codechef.com/t/trip2-editorial/36497/56 "2019-09-02T05:32:59Z")

</div>

Can you please help me tell why my solution is not working.

> **[CodeChef: Practical coding for everyone](https://www.codechef.com/submit/TRIP2)**
>
> Learn to code for free using our beginner friendly and interactive learning courses. Get all the practical skills required to excel at computer science. Start learning with CodeChef today and unlock your potential as a developer!

---

<div class="post-metadata">

**Author:** ![vishalpouras](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@vishalpouras](https://discuss.codechef.com/u/vishalpouras)\
**Post date:** [September 2, 2019, 5:33am UTC](https://discuss.codechef.com/t/trip2-editorial/36497/57 "2019-09-02T05:33:53Z")

</div>

Can anyone tell me what’s wrong with my backtrack code? It is quite readable.  
[My submission](https://www.codechef.com/viewsolution/26207799)  
Thank you in advance.

---

<div class="post-metadata">

**Author:** ![ssjgz](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ssjgz/32/346011_2.png) [@ssjgz](https://discuss.codechef.com/u/ssjgz)\
**Post date:** [September 2, 2019, 5:39am UTC](https://discuss.codechef.com/t/trip2-editorial/36497/58 "2019-09-02T05:39:58Z")

</div>

That’s not a link to your solution!

[Here](https://www.codechef.com/viewsolution/26207790) is a link to your solution.

This also fails the testcase:

```auto
1
10 2
-1 -1 -1 -1 -1 2 -1 -1 -1 2 

```

@ankit9437

---

<div class="post-metadata">

**Author:** ![ssjgz](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ssjgz/32/346011_2.png) [@ssjgz](https://discuss.codechef.com/u/ssjgz)\
**Post date:** [September 2, 2019, 5:58am UTC](https://discuss.codechef.com/t/trip2-editorial/36497/60 "2019-09-02T05:58:38Z")

</div>

There’s an out-of-bounds access at the line:

```auto
    if(arr[curr]==arr[curr-1] && curr>0) return false;

```

given the testcase:

```auto
1
43 2
-1 -1 -1 -1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 

```

which is probably interfering with the results. (This is likely not the only problem).

---

<div class="post-metadata">

**Author:** ![ssjgz](https://discuss.codechef.com/user_avatar/discuss.codechef.com/ssjgz/32/346011_2.png) [@ssjgz](https://discuss.codechef.com/u/ssjgz)\
**Post date:** [September 2, 2019, 6:00am UTC](https://discuss.codechef.com/t/trip2-editorial/36497/61 "2019-09-02T06:00:13Z")

</div>

This fails the testcase:

```auto
1
10 2
-1 -1 -1 -1 -1 2 -1 -1 -1 2 

```

---

<div class="post-metadata">

**Author:** ![kshitij\_789](https://discuss.codechef.com/user_avatar/discuss.codechef.com/kshitij_789/32/208155_2.png) [@kshitij\_789](https://discuss.codechef.com/u/kshitij_789)\
**Post date:** [September 2, 2019, 7:14am UTC](https://discuss.codechef.com/t/trip2-editorial/36497/62 "2019-09-02T07:14:46Z")

</div>

add the following in your code

import sys  
sys.setrecursionlimit(10\*\*9)

---

<div class="post-metadata">

**Author:** ![abhishek818](https://www.codechef.com/sites/all/themes/abessive/images/user_default_thumb.jpg) [@abhishek818](https://discuss.codechef.com/u/abhishek818)\
**Post date:** [September 2, 2019, 7:56pm UTC](https://discuss.codechef.com/t/trip2-editorial/36497/63 "2019-09-02T19:56:51Z")

</div>

This question is a classic example of Implementation being the hardest part.

---

<div class="post-metadata">

**Author:** ![rashu1999](https://discuss.codechef.com/user_avatar/discuss.codechef.com/rashu1999/32/6404_2.png) [@rashu1999](https://discuss.codechef.com/u/rashu1999)\
**Post date:** [September 3, 2019, 4:27pm UTC](https://discuss.codechef.com/t/trip2-editorial/36497/64 "2019-09-03T16:27:31Z")

</div>

[https://www.codechef.com/viewsolution/26188055](https://www.codechef.com/viewsolution/26188055)

Please help out with some cases. My solution gets only 70

[Previous page](https://discuss.codechef.com/t/trip2-editorial/36497.md?page=2)

[Next page](https://discuss.codechef.com/t/trip2-editorial/36497.md?page=4)
