Accepted Submission Link : codeforces.com/contest/1978/submission/266004537
@hdcutz29363 ай бұрын
Man seriously how u came up with this solution during contest?... Kindly tell about how u came up to the approach during videos as hints then it will be intuitive and interactive... other than this videos and qualities are gem... Kudos continue your work soon u will get recognized
@shaasshh3 ай бұрын
true, i had all of the solution on paper with no idea what to write in code it makes me feel so uselessssss....
@formidablechief273 ай бұрын
Okay first of all the condition for no/yes was comparitively easy to come across. The difficulty came in constructing the array I got that how we can construct the answer for max value of k, i just needed to find for other smaller values Then i started making all possible answers for n = 6 from the abs value i had got 1 2 3 4 5 6 6 5 4 3 2 1 Diff 5 3 1 1 3 5 So if my k is >= 10 I have to swap my first and last values So a[0] = n and a[n-1] = 1 and then i will try to find the remaining swaps by the decreased k in a shorter subarray Then i saw an issue arising for this case n = 6 and k = 4 My code was returning 1 2 4 3 5 6 Now since k < 10 i wont swap 1 and 6 And since k < 6 i wont swap 2 and 5 Then i realised that for n = 5, i am getting answer for k = 4 So i thought lets merge this two answers somehow For n = 5 and k = 4 i was getting 1 4 3 2 5 So k = 4 was solvable in odd length subarray So i thought, if k is less and divisible by 4, lets use odd length and not even So, i put a[n-2] = 5 And continued my loop for [1, n-3] Over here 2 and 4 got swapped and i got ans for 4 So i did this and i got correct for all even values of n Now i had to fix odd Because if i got n = 5 and k = 6, the ans was yes but k = 6 is solvable in even length subarray not odd So similarly i did Reduced size by 1 like for even Just here opposite % 4 != 0 So then after i did this i checked what output i was getting for n = 5 and n = 6 with all possible valid values of k (only those which would give yes) And they were right and so i submitted hoping it would not fail on pretest 2😂 But i was relieved once i saw running on pretest 3.
@formidablechief273 ай бұрын
Constructive algorithms are usually try out many testcases and make a pattern from it.
@deboshrutimukhopadhyay79253 ай бұрын
could you explain why this code is not getting accepted though I went with a similar aprroach #include using namespace std; #define ll long long int main() { int t; cin >> t; while (t--) { long long n, k; cin >> n >> k; // Check if k is odd if (k % 2 != 0) { cout