Getting Wrong Answer in "Longest non regular parentheses sub-sequence "codechef june cook off

I attended a programming competition(it has ended now). I don't know why my solution is giving WA, I read the editorial, saw other people solution but unable to find a flaw in my solution. Obviously I am missing somewhere. Please help!

Question Link

My Solution

My approach

If the pattern is non regular, answer is the same. Otherwise answer would be of length 1 less than the original pattern. Now the 1st lexicographic-ally smallest pattern can be obtained by removing one of the ')' from the first chunk(continuous sequence) of ')' in original pattern. 2nd lexicographic-ally smallest pattern can be obtained by removing one of the ')' from the second(if any) chunk(continuous sequence) of ')' in original pattern.And so on. And then say there are 'x' chunks of ')'. And we need to find kth lexicographic-ally pattern such that (k>x). For this case we move from backward, so for (x+1)th smallest pattern we remove '(' from first chunk of '(' (moving backward to front), for (x+2)nd we remove '(' from second chunk, and so on. The same logic is explained in tutorial here.

-------------Problems Reply------------

See I know you will feel bad when I will tell you what is wrong in your answer.

But the only thing wrong is you using gets(). Its 2015 no one uses it. I changed that to a scanf statement i.e delete this part of your code and

get(s);
get(s);
scan("%d",&k);

write this instead.

scan("%s%d",s,&k);

And Your code will be accepted. Next time try avoiding use of gets. use scanf, cin, something else.

Category:algorithm Views:0 Time:2019-02-19
Tags: algorithm

Related post

  • i need a formula for $ X % X % = $__i have 930.31*S36*(ab36+100%)__930.31x59.24%x1.24%=$552.44 getting wrong answer 2014-04-26

    XXX XXX XXX (Personal information removed) i need a formula for $ X % X % = $__i have 930.31*S36*(ab36+100%)__930.31x59.24%x1.24%=$552.44 getting wrong answer --------------Solutions------------- A Louise wrote: i need a formula for $ X % X % = $__i

  • CodeChef #3, Easy, Keep getting wrong answer 2011-02-06

    This is the problem I'm working on: http://www.codechef.com/problems/HS08TEST/ And this is my solution: #include <stdio.h> int main (void) { int withdraw_i; float balance_i; scanf("%d %f", &withdraw_i, &balance_i); if(withdraw_i % 5 ==

  • UVa 630 kept getting wrong answer 2012-02-01

    I have been working on the UVa 630 problem for 2 days, http://acm.uva.es/p/v6/630.html I have written a working code, however constantly getting the wrong answer result after the submission, my program works fine for the given input format and genera

  • Getting wrong answer for Project Euler #27 2011-07-15

    I'm working on Project Euler #27 in C++: Euler published the remarkable quadratic formula: n² + n + 41 It turns out that the formula will produce 40 primes for the consecutive values n = 0 to 39. However, when n = 40, 40² + 40 + 41 = 40(40 + 1) + 41

  • Pivot Table Calculation getting wrong answer 2012-12-29

    Hello this is my pivot table I need a calculated field I entered gives me the results of the grand total. I need the result of the form status. the right results should be the same as manual calculation I entered on the last column the the picture ab

  • Getting wrong answer when trying to get k subsets from Array in ActionScript 2014-06-11

    I'm working on a Texas Holdem game and i need to generate all possible k subsets from an Array of cards (represented as numbers in this example). This is how it looks so far: public function getKSubsetsFromArray(arr:Array, k:int):Array { var data:Arr

  • SPOJ wrong answer ADDREV 2009-09-26

    My code is quite simple and straightforward. I get "wrong answer" on submission though. I have no clue why that happens! Here is the code... #include<iostream> #include<string> using namespace std; void sum(string num) { int i,len=num.len

  • UVA's 3n+1 wrong answer although the test cases are correct . . .? 2012-03-08

    UVA problem 100 - The 3n + 1 problem I have tried all the test cases and no problems are found. The test cases I checked: 1 10 20 100 200 125 201 210 89 900 1000 174 1000 900 174 999999 999990 259 But why I get wrong answer all the time? here is my c

  • Wrong answer from Windows Calculator 2013-10-02

    The Scientific Calculator option gives the rigth answer for example 2+3*4 it gives =14 that is 2+12 =14 obviously. BUT the Standard Calculator option gives the WRONG answer =20 WHY ? There are no brackets so arithmetic rules say do the multiply first

  • CodeChef Daily Train Wrong Answer 2012-02-22

    So, in the last contest on CodeChef (February Cook-Off) I had what I thought was a working algorithm for this problem within about 15 minutes, but couldn't get the right answer. I tried forever, I've checked multiple things, I don't understand where

  • =IF gets the answer wrong 2012-05-27

    I have a simple spreadsheet which logs payments and alerts me if the invoice has been paid in full. I use an IF to check the result but I have a set of figures which seems to give the wrong answer. The spreadsheet is as follows: Cell A1 contains 53.2

  • Multiplying two matrices but getting the wrong answer 2012-02-15

    This is my matrix code. I am multiplying two matrices. One of the matrices is scalar (meaning diagonal elements are the same), but when I run this code, I am getting the wrong answer. static void Main(string[] args) { int[,] matrix1 = new int[3, 3];

  • what is non-grouping version of regular parentheses 2012-04-30

    Possible Duplicate: Non capturing group? From python re module document, i see: (?:...) Non-grouping version of regular parentheses. and (...) Matches the RE inside the parentheses. The contents can be retrieved or matched later in the string. What's

  • When were non-capturing parentheses added to Perl's regular expressions? 2010-08-08

    I am having a hard time figuring out the earliest version of perl where non-capturing parentheses are supported in regex patterns? Can I take this feature for granted for all versions of Perl5? --------------Solutions------------- I dug out Perl 5.00

  • Where can I get good answers to my Perl-related questions? 2008-09-19

    AFAIK one of the objectives of Stack Overflow is to make sure anyone can come here and find good answers to her Perl related questions. Certainly beginners would ask what is the best online source to learn Perl but others might just want to ask a que

  • algorithm to find longest non-overlapping sequences 2011-01-04

    I am trying to find the best way to solve the following problem. By best way I mean less complex. As an input a list of tuples (start,length) such: [(0,5),(0,1),(1,9),(5,5),(5,7),(10,1)] Each element represets a sequence by its start and length, for

  • Most appropriate way to get this: $($(".answer")[0]) 2011-01-29

    Suppose I want to get the first element amongst all the elements of the class ".answer" $($(".answer")[0]) I can do the above, but what is the best balance between elegance and speed? *changed the question to reflect the current discussion ----------

  • Recursive, Divide-and-conquer algorithm for longest non-decreaseing array of numbers 2011-10-11

    I'm having some serious problems for this problem. I need an recursive algorithm that "divides and conquers" that tells me the length for the longest non-decreasing array of numbers. Personally, I would choose to use this code that I wrote before rea

  • Can I perform autocorrelation / lag analysis on a zoo object in R with non-regular time steps? If so, how? 2012-01-23

    Can I perform autocorrelation / lag analysis on a zoo object in R with non-regular time steps? If so, how? The only other post I could find here dealt with regular time series. I have a sequence of observations taken at irregular time steps. For exam

  • Javascript Regex and non-capturing parentheses 2012-03-29

    I'm a bit rusty on my regexp and Javascript. I have the following string var: var subject = "/admin.php?page=settings&tabs_added[114787535263592]=1&tabs_added[217770811582323]=1&tabs_added[198738186831542]=1" I want to extract 11478753526

  • FFT algorithm getting wrong sound frequency value 2012-11-15

    I have performed a FFT algorithm(it is partially MIT) on a 440Hz sample link to the sound sample ttp://www.speedyshare.com/R6d9g/440.wav. But I get wrong sound frequency -> 510Hz. 1.Is the byteArray containing .wav is correctly converted into 2 do

  • want to use quotient and get the answer with decimal place 2013-06-06

    excel 2010 I want to use quotient and get the answer with decimal place. Example 3456 / 2687 I require an answer of 1.2870. But I am recieving a whole no. of 1. I try to change the format cells to 4 decimals, but recieve the answer of 1.000 What do I

  • Excel calculates the wrong answer 2013-08-27

    Type 35.4 in cell A1. Type 35 in cell A2. Type =A1-A2 in cell A3. Expand the decimals out and you will see the answer is not .4 as it should be. Excel goofs up on a few other numbers too, such as 24.4 and 24. Can someone please explain this to me? It

  • why is ms security essentials allowing trojans to get onto my computer it is regularly updated 2014-09-19

    i am getting trojans on my computer my os is xp it is regularly updated as is security essentials also when i try to update it will not update se and i keep getting messages telling me to clean up any help welcome george --------------Solutions------

  • Do theoretical computer science topics, such as regular vs non-regular languages, the pumping lemma, and grammars have "real world" development applications? 2009-01-20

    I'm familiar with the real world applications of finite automata and regular expressions, but topics such as these other ones are giving me more problems as I'm not seeing any real world applications. --------------Solutions------------- These things

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.092 (s). 11 q(s)