TTUPLE - Editorial

Can anyone please help me with this where this will give wrong answer
Thanks in advance …please.
https://www.codechef.com/viewsolution/34458292

Might be in case of multipication first and then adding it with specific number to all 3 elements of the tuple, you might be checking the remainders of all three numbers to be same and are divisible by same factor but this will not work for all test cases…
eg- 8 4 5
21 9 12 (multiplying all 3 numbers by 3 first and then adding -3 to it)

Hey! Thanks for your reply but I have ran these test cases in my program and they are working. The case you told, first multiplication and then addition, I have used linear equations to calculate the possibility of getting done in 2 steps.
Equations are…
a-pxi = b-qxi = c-rxi, where i is the number to be multiplied first to all three numbers such that the new differences are all equal.
from these equations you will get
i= (a-p)/(b-q) = (b-c)/(q-r);

I had thoroughly went through all my cases I used… First I would check that can this tuple be resolved by only addition or only multiplication. if the answer from both is 3, i will go for ADD->MULT and MULT->ADD which can give me answer 2.
And then take all permutations of sequence of operations to be preformed in both functions. But there might be some very small bug that I could not find, but the editorial solution is ideal.

One of the worst question I have ever faced. Total waste a time.

um, read the editorial fully. I specifically mentioned the special case

I can’t figure out why my solution giving TLE for 10 points, but getting AC for rest 90.
Here is my solution: CodeChef: Practical coding for everyone

my code has passed all cases given by @pavankalyan_93, but still getting TLE on subtask 1.
Can anyone help
my solution : CodeChef: Practical coding for everyone

You took it to next level

What is mask in editorialist code…?

1 Like

Can anyone help me where this fails?
https://www.codechef.com/viewsolution/34095193

My 75 lines of readable AC code … hope it helps!

#include <iostream>
using namespace std;
#define int long long

bool solve2a(int a, int a1, int b, int b1, int c, int c1) {
	if (b != 0 and b1 % b == 0 and c1 * b == (c + a1 - a) * b1) return true;
	
	int r = (a1 - b1), d = (a * b1 - a1 * b);
	if (a != b and a1 != b1 and r % (a - b) == 0 and d % (a1 - b1) == 0) {
		r /= (a - b);
		d /= (a1 - b1);
		return (c1 == c + d or c1 == c * r or c1 == (c + d) * r);
	}
	return false;
}
bool solve2b(int a, int a1, int b, int b1, int c, int c1) {
	if (a != 0 and a1 % a == 0 and c1 + b == c * a1 / a + b1) return true;
	
	int r = (a1 - b1), d = (a * b1 - a1 * b);
	if (a != b and r % (a - b) == 0 and d % (a - b) == 0) {
		r /= (a - b);
		d /= (a - b);
		return (c1 == c + d or c1 == c * r or c1 == c * r + d);
	}
	return false;
}
bool solve2(int a, int a1, int b, int b1, int c, int c1) {
	return solve2a(a, a1, b, b1, c, c1) or solve2b(a, a1, b, b1, c, c1);
}

int solve() {
	int a, b, c; cin >> a >> b >> c;
	int a1, b1, c1; cin >> a1 >> b1 >> c1;
	int d1 = (a1 - a), d2 = (b1 - b), d3 = (c1 - c);
	int r1 = (a ? a1 / a : 0), r2 = (b ? b1 / b : 0), r3 = (c ? c1 / c : 0);
	bool e1 = (a == a1), e2 = (b == b1), e3 = (c == c1);
	bool u1 = (a != 0 and r1 * a == a1);
	bool u2 = (b != 0 and r2 * b == b1);
	bool u3 = (c != 0 and r3 * c == c1);

	if (e1 and e2 and e3) return 0;
	
	if ((e1 and e2) or (e2 and e3) or (e3 and e1) or
		(e1 and ((u2 and u3 and r2 == r3) or d2 == d3)) or
		(e2 and ((u1 and u3 and r1 == r3) or d1 == d3)) or
		(e3 and ((u2 and u1 and r2 == r1) or d2 == d1)) or
		(u1 and u2 and u3 and r1 == r2 and r2 == r3) or
		(d1 == d2 and d2 == d3)
	) return 1;

	if ((e1 or e2 or e3) or
		(d1 == d2 or d2 == d3 or d3 == d1) or
		(d1 == d2 + d3 or d2 == d1 + d3 or d3 == d1 + d2) or
		(u1 and u2 and u3 and (r1 == r2 * r3 or r2 == r1 * r3 or r3 == r1 * r2)) or
		((u1 and u2 and r1 == r2) or (u2 and u3 and r2 == r3) or (u3 and u1 and r3 == r1))
	) return 2;

	if (solve2(a, a1, b, b1, c, c1) or
		solve2(a, a1, c, c1, b, b1) or
		solve2(b, b1, a, a1, c, c1) or
		solve2(b, b1, c, c1, a, a1) or
		solve2(c, c1, a, a1, b, b1) or
		solve2(c, c1, b, b1, a, a1)
	) return 2;

	return 3;
}

signed main() {
    int t; cin >> t;
    while (t--) {
        cout << solve() << '\n';
    }
    return 0;
}

https://www.codechef.com/viewsolution/33924984
i bet you cannot beat me
still wondering how it gets accepted

Thank you! :slight_smile: I would say it ended up being a Pyrrhic victory, it was a war between the problem and my stubbornness, sort of pointless war.

The truth is that initially I embarked on a different road to the solution, spent probably 10+ hours on it, but it always got only WAs! So I rested for few days, and finally did a last attempt to preserve my honour :slight_smile: and started a second fight, one I won with luck I guess.

In total it was around 15 hours spent to cover all cases.

In general I don’t think this problem brings many useful things/insights on the table. For me it was a test of persistence and dedication, probably because I am not smart enough to invent a simple solution.

1 Like

Hi why we are using 2power 3. also why are using bit AND?

Definitely, I didn’t like the problem either. And as the constraints are small (there are only 2 allowed operations on a 3-length tuple), I tried the randomised approach. There were quite a lot of WAs before a 100 pts AC (randomised approach doesn’t guarantee a correct answer each time, especially if there are 1000 test cases per test file), but I think it was worth it. I would still prefer the WAs to investing endless hours for a seemingly uninteresting problem.

I tried submitting the random solution in practice and received AC after the 12th attempt. Link

2 Likes

THIS IS MY CODE WITH ALL EXPLANATIONS …
HAVE A LOOK AT IT …

https://www.codechef.com/viewsolution/34342471

1 Like

What exactly did you do in your randomized solution? Can you explain?

Thanks alot :slight_smile:

I tried almost billion times no luck so far. :frowning:
UPDATE: Subtask 1 is failing now !!!

https://www.codechef.com/viewsolution/34480590
please see what the issue is. comments are used for understanding the code.