I used next_permutation and get AC i used next_permutation and got TLE test 2 1 1 1 1 1 1 ans: Yes ... Edited by author 06.12.2014 19:30 I solve without loop but is return WA#4 There is my algorithm : if in list has 1 , 2 , 3 together always "Yes" otherwise "No" am I right or any case is there ? Edited by author 09.08.2017 09:41 Edited by author 09.08.2017 09:42 You can get six combinations with two a's and two b's You can get six combinations with one a and five b's Sorry but I don't understand what do you mean ! Give me Test Case #4 0011 0101 0110 1001 1010 1100 That is six 000001 000010 000100 001000 010000 100000 That is also six 012 021 102 120 201 210 And that is six Answer is No , Correct ? 0011 0101 0110 1001 1010 1100 That is six There are at LEAST, 70 tests. int main(int argc,char *argv[]){ //freopen("data.txt","r",stdin); int n,i,key = 0,count = 0; char p[105],input[105]; scanf("%d",&n); getchar(); for(i = 0; i < n; i++){ scanf("%c",&input[i]); getchar(); } input[i] = '\0'; strcpy(p,input); while(next_permutation(p,p+n)){ if(strcmp(p,input) == 0){ break; } else { count++; if(count >= 5){ printf("Yes\n"); return 0; } } } if(count >= 5){ printf("Yes\n"); } else { printf("No\n"); } } count should be at least 6 :) next_permutation() generates distinct permutations of a given iterable object (vector, string, etc). Just make 6 permutations, and save each of them in a set<vector<int> >. Finally, check if the size of the set is 6, because the set only saves different elements. Pretty easy solution. wrong ans #26.Is there any test. 5 1 1 1 2 1 answer is "No" Why? 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 1 1 2 // code deleted Edited by author 17.06.2015 01:38 4 1 1 1 1 No 4 1 1 2 2 Yes 4 1 1 1 2 No 4 2 1 1 1 NO Try this tests. It helps me. But I have WA #55 and I need a help Edited by author 17.06.2015 02:16 I'm wondering if anyone knows the 13th test... i think it's some kind of special case. 3 1 1 2 NO 3 1 2 3 Yes 2 1 2 NO These are 3 test i suppose cause, it doesn't specificate that we have multiple test cases in one input. Am I right? No, you are not right. There is just one test case in every input, multiple tests were written just for you. Test: 7 1 1 1 1 1 1 2 YES Test: 4 1 1 2 2 Ans: Yes Edited by author 11.11.2013 15:19 4 1 1 2 2 Yes cause: 1122 1212 1221 2121 2211 2112 Edited by author 16.12.2013 23:57 i thinks these tests are not suitable for 13th s. 'casue i passed these ,but get 13th wrong. Two-Eight-Nine.Thanks...!!! i had 9 wroung attempts, 10 was AC lol My code: /* Code deleted. */ we get the WA12. What's the problem? Edited by author 09.11.2013 22:57 You will easily get overflow... 100! ~ 9*10^157 which is a "little" too big Oh, right! Thank you very much. It turns out I have the wrong formula? Thank you very much. I change long long to double. ;) This problem is possible to solve without any formulas - just using one sorting of 3-element array and 3 IF statements - so, you won't have problems with overflows Please, could you explain a bit more your approach? Edited by author 05.09.2014 03:37 Just got A.C Just need to change all variable and return values to double. Count number of 1s 2s and 3s. Take the factorials of these numbers however you feel right, divide by total length,n. Please, could you explain a bit more your approach? Thanks you very much! I did this: 4 If. One for n > 5, the another threes for n == 5, n == 4 and n == 3. tried tons of optimizations but Scala solution still TLE, any suggestions? ok so I got AC the key difference seems to be in using correct way to read the input if I use readLine().split(' ').map(_.toInt) then it always TLE but if I read input using Java Scanner: val sc = new Scanner(System.in); .... sc.nextInt() ... then it works fine Edited by author 31.03.2014 08:45 I also have many problems with scala. My scala code runs two times slow than the corresponding java code. Sometimes it's really hard to optimize. My tips (in general, not specifically about this problem): * don't use vars if not really necessary * foldLeft and similar functions are slow unfortunately (although I tend to use them anyways, only switch to for when I got a TLE) * array initialization is REALLY slow especially if you use fill (much more slower than java). try to keep your arrays as small as possible. For example sometimes it's possible to keep only the last two rows of a matrix. if you deal with n>5 and n<=5 cases separately. The former does not require any factorial calculation Edited by author 18.02.2014 14:04 Ребята будьте внимательный когда читаете условия. Я потратил пол часа пока понял что нужно составить не менее 6 а не не менее n слов... I test the 13th case which has been given before but it gives WA for test 13. please can any body tell me what's the wrong |
|