after reading statement of D 10 times, i can confirm i still didn't get anything. you gotta have peak mathematical reasoning to actually understand that.

I was trying to use openmp's parallel functionality, does cf supports it? i am not getting any error nor can i observe any significate difference in execution time.

without pragma 149232334

with pragma 149233499

thanks for trying your code is sooo clean.

I tried something similar, but because i am not pro like it took some time for me to code it well. basically what i did is pushed all the points that has an direct answer into queue. (more like pushed the outer layer of points in queue first). then i translated outer layer's answers to inner layers. but i got Wrong answer on Test 9. can you help if you find anything sussy here?

Edit: no worries got accepted. it. was a minor issue :(.

yes you are right only difference can be made by removing minimum gaps. also need to make sure there are two ways to remove each gap that is not the left most. and also the way i implemented it didn't hurt to check every index, so to keep code a bit simple i didn't think of optimizing on that

i thought too what ever i was thinking should work but it didn't. then i changed my perspective and did some implementation with multiset to check what would be answer if i change $$$i^{th}$$$ exam date.

I still don't understand, how are you referring it similar to a DFS? if i am not wrong, in bellman Form, we really don't follow edges in any order right? it might be possible that we are taking some other path's to edge to point to one of node in our actual path ( i know there can be multiple ), and it could mess up all the negative cycle. why is this not happing in the above mentioned solution? is there any more indepth reference for this ? i am having hard time grasping it :(.

i can't wrap my head around the parents, can you help me understand why parents will always lead to the right path?


lets say you have a $$$2 \times 2$$$ square of following configuration somewhere in your canvas...

 1 2
 3 3

lets say your code pointed both cells to $$$(1,1) \to (2,1)$$$ and $$$(1,2) \to (2,2)$$$.

but i guess in reality it should have been $$$(1,1) \to (1,2)$$$ and $$$(1,2) \to (2,2)$$$ or something but not the first case.

how do you deal with such cases ?

MikeMirzayanov please consider my request.

i want to roll back my user name :).

can we check bijection using prufer code of the trees after rooting them onto their respective centroids?

On infiniteproMemes related to CP, 3 years ago

is he trying to imitate this?


I am sorry but i assumed that the handle change features was temporary magic feature. you wrote in the accouncement that we can request to rollback change.

i am requesting you to roll back my handle to previous one ' sirearsh '.

thankyou very much.


i thought changing handle was part of temporary magic can anyone help me to revert settings? MikeMirzayanov ?

thanks, i understand now that was a shitty mistake and a bad habit.

thanks, i didn't account for the null character. :(.

what is limit for memory allocation in C++ during runtime?

my solution for B failed system test because i was allocating (3*500*500) memory at runtime in worst case scenario.

indeed, and i know you from codechef discuss. :D


looks like i supercomplicated B and C. :(

did you also overcomplicated solution for B or are you normal?

expected solution was if all elements are distict print "NO" else "YES".

On PrinceOfPersiaHello 2015 Editorial, 4 years ago

I know this comment a bit stupid.

but i can't reason why this code is failing for F? i was practicing centroid decomposition this is the first problem i got stuck at.


Thankyou if you can help.


AC submission.

thankyou this a very handy snippet.

i was almost there, unfortunately i didn't knew nlogn approach for LIS :(((.

there were only two you could have turned the strings into...

either 10101010

or 01010101

this is not youtube comment section.

its funny, you are a red coder. and you are asking us about cin and scanf?

Finally did it, i am sorry i didn't understand your logic at first go. now when i anaylyzed properly i found out it how it is working it a great implementation. and i surely learned something out of it.

thankyou for being so helpful. keep up the spirit.


vals is sorted in descending order.

the the set with the bigger (maximum value) comes first in set. so i am erasing the begin because begin has the current maximum. :(

i am having a implementation problem what if there are more than one maximum equal to maximum(maximums)?

i think this is why my new code according to you failed on test 9

I have doubt you didn't changed minimum at all ?

why did you worked on maximum only?

oh great implementation thankyou.

my dumb ass was thinking that the answer's graph would be something like \/ in shape and i could apply ternary search on it. i later found out that it was stricly decreasing and then strictly increasing but it also had some portion parallel to x-axis. that where it fucked up... i was clue less after that. :(

All elements were unique you just have to find a row and column with same first element and now you know that is the first row and column...

elements for first row are going to be first element of columns and same for the elements of columns.

How to approach C?

was ternary search going to help in any way?

its funny how every one made same mistake of stopping iteration on stisfying mid rather than both limits.

what is a based contest?

lets have a good night's sleep then before rating changes.

what is your valid function of binary search?

valid in the following sense:

while (lo<hi) {
  mid= lo+hi/2;
  if (valid(mid)) lo=mid;
  else            hi=mid;

i meant that "saying something disturbed his mental peace" is his own issue. he cannot blame it on that "something".

you need to work on your "mental peace" then.

that is your personal issue.

in binary seach we make jumps from mid to val that we need..., so when ever we come to some point. we just need to check weather to jump forward or backward.

to jump foreward we need to put some value at that cell that is less than x. choices that we have is n-x for this cell in array. to jump backward we need to put some value at that cell that is greater than x. choices we have is x-1.

now if you make two jumps forewards, choices to put values in those cells are n-x for first cell and n-x-1 for next cell. total choices are (n-x)*(c-x-1)

after you fill and calculate all cells where you jumped. the permutation of remaining cells doesn't matter. you can permute all the rest of cells.

eg 4 1 2

we jump to 2 (4+0/2).

val[2] == 1(x) [it is given value at 2 is 1]

choices that we have to fill jumping indexes is 1 (only 1 was filled no other choice).

ans = 1 * fac(3), [3 is number of cells whose value doesn't matter]

ans = 6

i dont think so.

are you sure your code is ignoring even index (in reference to the subsequence) value if that is situated at last index?

On shishyandoCodeforces Round #671, 4 years ago

i don't see the right reply

it was given in statement every cube should have one of it's corner as stair. orange cube doesn't have any corner as stair, thus not nice.

Edit here is statement All squares should fully consist of cells of a staircase.

On shishyandoCodeforces Round #671, 4 years ago

testers are simp to not add that in pretest.

try making out patterns on paper and see how the pattern goes, they gave un hint in sample that answer was going to be in 1 to 30 only. so you could simply precompute these 30 values.

On shishyandoCodeforces Round #671, 4 years ago

why are you checking for odd values in both cases of N ?

if N is odd 1 will have the change to make the last element and hence he would want atlest one odd value,

other wise second would want atleast one even value.

but you only checked for odd.

either way i don't think if change in 500 points is going to make a drastic change in ranking anyway. you will still be under 400 or something (I guess).

On shishyandoCodeforces Round #671, 4 years ago

for D,

look at sample cases and do exactly.
take two pointers i and j
initialize i = 0, j = (n / 2)
now alternatively add them to another vector.
check answer count.
print it.
On shishyandoCodeforces Round #671, 4 years ago

looks like we tried same shit for D2 at first attempt lol.

On shishyandoCodeforces Round #671, 4 years ago

B should be closer to C, and D2 should have been lower than D1. there is no difference. rest is okay.

On shishyandoCodeforces Round #671, 4 years ago


On shishyandoCodeforces Round #671, 4 years ago

what brute force?

On shishyandoCodeforces Round #671, 4 years ago

more simply you can get all ratings to x except for the last guy, and compensate it all on the last guy to make whole difference 0. and then do last guy, make him compete with any one and make last guy infected as he is the only one remaining. that is case for 2, (only 2 operations needed).

if the last guy == x, he was already infected, that is case for 1 (only one operation needed) else 2.

more formally

all elements == x: output 0

if (count x in array > 0 || sum == x) output 1

else 2

On shishyandoCodeforces Round #671, 4 years ago

I was hoping one graph problem among C — E, but there was none, instead it was a puzzle game as OP said.

On shishyandoCodeforces Round #671, 4 years ago

yes, look at how height of stairs is changing.

starts with 1, and then height = (height * 2) + 1

and they gave us the higher limit of this in sample. look at my submission for more help.

On shishyandoCodeforces Round #671, 4 years ago

1 step only,

change rating +1 for first guy and -1 for second guy.

On i.eCodeforces Round #669, 4 years ago

You are not alone, for betterment of my mental health and physical safety of my laptop i headed out of the room after first WA.

On i.eCodeforces Round #669, 4 years ago

I don't know good or bad but why was Problem A laughing at me :sob:.

would you explain what you are doing in your code?

no there could be multiple answers. so finding one possible and then checking if it matches input is obviously wrong.

cases of for having '1' is ambigous, but have a '0' is obvious. why are you considering '1's first?

same pinch

shouldn't have wasted that much time on B, C was waaayyy easiear and doable than B.

On tweetyO(1) runtime prime checking, 4 years ago

Thank you. I did get the basic idea what is going on here.

if you just subtract 1 from all the elements, you will have little different array.

but now, you need to find all the subarrays with count 0.


here is how to deal with this problem from this perspective

On tweetyO(1) runtime prime checking, 4 years ago

You can see i am new to all this, i also don't have much backgroud in this. but i am trying to learn. please explain me breifly what you meant.

On tweetyO(1) runtime prime checking, 4 years ago

in this code i added another simple sieve struct, and compared both

a@a:~/Desktop/Cp$ ./a.out <- sample count 1e6
Runtime ans: 86783. Elapsed (ms): 29
Compiletime ans: 86783. Elapsed (ms): 13
a@a:~/Desktop/Cp$ g++ test.cpp <- sample count 1e7
a@a:~/Desktop/Cp$ ./a.out
Runtime ans: 877166. Elapsed (ms): 124
Compiletime ans: 877166. Elapsed (ms): 134

i don't think this is a satisfactory change ?

On sshwyRCodeforces Round #664, 4 years ago

rank 1 guys code is very clean to understand.


sure thankyou


Yeah i know how bad it can feel, get off the PC for better.


i don't think so,

it so convient except countOf1, countOf2 am using _1 , _2. isn't that easiear and faster to type?


well i don't think anyone can help, you are not in a school where teacher can be linient.


are they illegal?


well well well,

this is a huge difference !!!!, i never though this would make this much difference.


that is cruel.


why is this solution taking so long in time.

as i only used static array and linear code.? plus no dynamic objects.

Nice reply LoL.

in :
out :
1 2 1 1 2

you can see this test case says it all. 2 set was starting from 0 and your code is giving the next element as 0 also in the second subsequence.

here is an alternative solution to problem C, simple brute force for all possible s, and then using 2sum to calculate.

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int tt; cin >> tt;
	while (tt--) {
		int N; cin >> N;
		vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i];
		int ans = 0;
		sort(A.begin(), A.end());
		for (int k = 2; k <= N * 2; k++) {
			int i = 0, j = N - 1;
			int tans = 0;
			while (i < j) {
				if (A[i] + A[j] < k) i ++;
				else if (A[i] + A[j] > k) j --;
				else {
					tans ++;
					i ++; j--;
			ans = max (tans, ans);
		cout << ans << '\n';
	return 0;

but it will not let hard word of people be soiled like mine. what else do you expect?


i will cry, if they declare this contest unrated.


This my best ever performance, please it shouldn't be unrated...

so s = s + '9'; this statement can run in either $$$O(1)$$$ time or $$$O(n)$$$ time. if memory is available it will run $$$O(1)$$$ time, but if mmemory not available in contiguous manner in memory this statement will take $$$O(n)$$$ as i said it will copy the whole string to a place in memory where is avalable.

so it is not truly $$$O(n^2)$$$.

it depends on the collsions (when contiguous memory is not available and compiler will perform $$$O(n)$$$ operation.) and your code at the time of contest got more collisions than when you ran it after contest.

it might have something to do with may be that memory is under more demand during a contest in comparison to after contest.

if your code's string get assigned a memory place from which a contiguous space which required is available in that your code will run in 30ms.

If you want to be safe from next time then becareful while using dynamic memory allocations. and reserver memory before hand as much required in one statement. like most common mistakes like these are using unordered_map. link.

i have a friend who uses char arrays instead of string to be extra safe.

because your test case is too small here are possible answers to you test case

1 2 3 = -3

1 3 2 = 8

2 1 3 = -3

2 3 1 = -3

3 1 2 = 8

3 2 1 = 8

there is no 9.

i don't see how you are getting 9..?

no it is not.

we are only starting from the leaves. and that is the logic.

Explain how is your expected result is 9?

I am not sure but it has something to do with dynamic strings you are using, in first submission you code might have encounter memory issues. like you are making a string of size (maxN). when ever you push a char into it. string needs a contiguous free space to instert if it is not there then string will move the whole string to a place where memory is available. and this operation takes O(n) time to execute.

that means complexity of your code could have crossed $$$N^2$$$ in this way on multiple occassions.

look at this submission :


in this code i reserved a contiguous memory space of N for my string at very first. and look it only took 30ms to execute while your code did same in ~1000ms.

can anyone help me with this solution for problem D?

yes i found that lately... it was introduced quite whem i joined...

I am very demotivated... where is button to delete account?****

May be they don't want us to use Python... XD

you can't blame it on education system ..... NO

You don't know how stressfull it was, and now predictor says imma get 93 rating increase. so i would never want it go unrated.

anyone ? this python code is getting runtime error on 27th test (last one). i am new to python and have no idea why is this happening.

well input is based on indexing from 1 to N, where as vuvoh's code is reading input from 0 to N minus 1. like input will consider nodes 1, 2, 3, 4 but vuvoh's code will consider them as 0, 1, 2, 3 this is the reason he did x + 1 and y + 1 in output statements.

my rating didn't started with 1500 ?