iron_nicko's blog

By iron_nicko, history, 15 months ago, In English

Question :

Find the minimum amount of Prefix-Strings
needed to make string B from the given list of strings A.

Input :

4
abc ka efgh k
efghkabc

Output: 3

Constraints:

1 <= N <= 100
1 <= |A| <= 100
1 <= |A[i]| <= 100
1 <= |B| <= 100
My Code

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By iron_nicko, history, 15 months ago, In English

This question confused me during the contest. I thought maybe if I go till $$$1e6$$$ I should be fine, but I got a TLE, no surprises. Then I optimized the code using two pointers, added in some memoization, and prime factors, and tried again with $$$1e6$$$, It failed no surprise. By this time I realized maybe if I tried the "normal" way till $$$1e4$$$ should work and I got accepted.

But "craziness" started after the contest when I tried to submit my optimized code with a limit of $$$1e4$$$, and to my surprise it passed and it was faster than the C++ submission! Curiously, I increased the limit to $$$1e5$$$ and it passed again but it was pretty close to a TLE.

Exhibit: 216349728

I tried to explain what I have done, but if somebody could help me point out how this code could run even till $$$1e5$$$ I'd appreciate it.

Explained Code: 216355374

Please excuse my English :}

Full text and comments »

  • Vote: I like it
  • -3
  • Vote: I do not like it

By iron_nicko, history, 16 months ago, In English

214876910

This is just unfair that my PyPy submission got TLE! Can this be reviewed?

Full text and comments »

  • Vote: I like it
  • -27
  • Vote: I do not like it

By iron_nicko, history, 21 month(s) ago, In English

Hey, I know the contest was postponed, but I was trying to solve this question:

Question:

Consider the integer sequence A[], where the elements are first N natural numbers in order.

You are now given two integers, L and S. Determine whether there exists a subarray with length L and sum S after removing at most one element from A.

A subarray of an array is a non-empty sequence obtained by removing zero or more elements from the front of the array, and zero or more elements from the back of the array.
1 <= N <= 10^9
1 <= L <= N - 1

I came up with something like this:

My Code

Test Cases with the answers:

3
5 3 11 # YES
5 3 5 # NO
5 3 6 # YES

My code seems to pass the initial test cases, but I'd like to know if this will work for all cases. Please let me know if this is correct.

Updated Code

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it