TTUPLE - Editorial

g1g1

Can anyone help me with my code??? I have used the same logic in my code.
#include
#include
#include
using namespace std;
int main() {
// your code goes here
int t; cin >> t;
while (t–) {
int ip1[3]; int ip2[3];

	// p, q, r
	for (int i = 0; i < 3; i++) {
		cin >> ip1[i];
	}

	// a, b, c
	for (int i = 0; i < 3; i++) {
		cin >> ip2[i];
	}

	// differences
	int d = 0;
	set<int> diff;
	vector<int> v;
	for (int i = 0; i < 3; i++) {
		if (ip1[i] != ip2[i]) {
			d++;
			diff.insert(ip2[i] - ip1[i]);
			v.push_back(i);
		}
	}

	if (d == 0) 
		cout << 0 << endl;

	else if (d == 1)
		cout << 1 << endl;

	else if (d == 2) {
		if (diff.size() == 1) 
			cout << 1 << endl;
		else {
			int p = ip1[v[0]], a = ip2[v[0]], q = ip1[v[1]], b = ip2[v[1]];
			if (p != 0 && q != 0 && a%p == 0 && b%q == 0 && a/p == b/q) 
				cout << 1 << endl;
			else 
				cout << 2 << endl;
		}
	}

	else if (d == 3) {
		int p = ip1[0], q = ip1[1], r = ip1[2], a = ip2[0], b = ip2[1], c = ip2[2];
		bool cond1, cond2, cond3;
		cond1 = (p != 0 && q != 0 && a%p == 0 && b%q == 0 && b/q == a/p);
		cond2 = (q != 0 && r != 0 && b%q == 0 && c%r == 0 && c/r == b/q);
		cond3 = (r != 0 && p != 0 && c%r == 0 && a%p == 0 && a/p == c/r);

		if (diff.size() == 1) 
			cout << 1 << endl;
		else if (p != 0 && q != 0 && r != 0 && a%p == 0 && b%q == 0 && c%r == 0 && a/p == b/q && b/q == c/r)
			cout << 1 << endl;
		else {
			if (diff.size() == 2) 
				cout << 2 << endl;
			else if (cond1 || cond2 || cond3)
				cout << 2 << endl;
			else {
				int d1 = (b - a), d2 = (q - p), d3 = (c - b), d4 = (r - q);
				if (d2 != 0 && d4 != 0 && d1%d2 == 0 && d3%d4 == 0 && d1/d2 == d3/d4)
					cout << 2 << endl;
				else 
					cout << 3 << endl;
			}
		}

	}

} 

return 0;

}

I also got the logic adding one by one edge cases but can’t get AC.
my code is working fine on compiler but while submitting gives runtime error.
idk why??
any help is much appreciated.
here is my code >>>
https://www.codechef.com/viewsolution/34708029

make sure to not divide by 0 at any instance.

1 Like

runtime error means somewhere u r doing division by 0,check that
and for wa ig
check the case
-10 2 -1
3 3 2
ans-2

1 Like

I checked division by zero for each case and for your given test case its giving 2.
I have tried several such possibilities.

Yeah i have checked division by zero for every single case…and i didn’t find anything new in editorial thats not in my code.

1 Like

Thank you so much :heartpulse: :heartpulse: :heartpulse: :heartpulse: