Общий форум #include <iostream> #include <cstdlib> #include <deque> using namespace std; int main() { int h; char s[200001]; scanf("%s", &s); int n=strlen(s); deque<char> v (s, s + n );
if(v.size()==2 && v[0]==v[1] ) return 0; b: h=2; for(int i=0; i<v.size()-1 ;i++) if(v[i] == v[i+1]) { v.erase(v.begin() + i); v.erase(v.begin() + i); h=1; } if(h==1) goto b;
for(int i=0; i<v.size(); i++) cout << v[i];
return 0; } Hello, If you are still working on this, let you know that it can't be solved with erase. I implemented a similar algorithm in Java which goes through the string and deletes the successful characters and it also got TLE on test 6.The easiest way is removing the successful characters as you read them. nc->new character from the input. if(i!=-1&&c[i]==nc){//new char is equal to the char at the end of the string, remove it i--; }else{ //add the new char to the string i++; c[i]=nc; } Hope this helps You got TLE because deque has poor deletion performance on positions other than the front and back. very similar to the NP-complete problem 3-dimensional matching (3-сочетания) Yes, this problem is NP-hard. i have a not brute force solution. The conditions of the problem impose restrictions on the graph But your algorithm is wrong :) We added more tests and now you have WA. Thank you! You can solve the question very fast with appropriate precomputed values. The sequence is known as the Stern-Brocot sequence, I was not aware of it before! Edited by author 12.07.2019 04:29 #include<iostream> using namespace std; int main(){ int petr,a,taxi,b; int temp; while(cin>>petr>>a>>taxi>>b){ if(petr>=taxi)cout<<petr<<endl;
else{ temp=taxi-petr; if(a<=b){ while(temp>b){ petr+=a,taxi-=b; temp=taxi-petr; } cout<<petr+a<<endl; } else{ while(temp>a){ petr+=a,taxi-=b; temp=taxi-petr; } cout<<taxi<<endl; } } } } i pass all the test that the discuss give but i still get wa at #4 could u give me some new test? if(a<=b) ---> if(a<b) but i still get wa at #13 for exanmple try test 1000 2 2000 3 the right answer is 1400 but your prog output 1402 or try this 1 2 12 3 right is 6 but yours is 7 Edited by author 20.03.2008 17:57 thanks for 2nd test, it really helpfull) Thanks a lot... ^_^ // solve #include <iostream> using namespace std; int main() { int a,b,c,d; cin>>a>>b>>c>>d; while(a< c) { if(a+b > c) { a=c; break; } a= a+b; if(c <= a) { break; } c = c-d; }
cout<<a<<endl; return 0; } First and foremost, is seems to me that there are only two test cases: (1) the sample case (2) an 8MB test case For WA this test helped me: input: 2 bbaadbdcc aadbdbcbadb aadbdbcbadb bbaadbdcc output: Case #1: 3 2 5 Case #2: 5 2 3 For TLE: parse the input I optimized all sorts of things but eventually I ran out of ideas. Then I remembered someone else was mentioning he submitted the same code again and passed got rid of TLE. Also, from my own experience, I noticed there was a sort of "randomness" in the time execution from one submission to another. (I was able to detect it by killing my program after processing 6MB of the input file.) At this point I was seriously considering speeding up the input reading part of my program using custom code instead of stdin.h. I got 760ms for processing 6MB of the input and I said to myself I'm really close: my code should run in 1.040s. And so I decided to parse the input: I got AC in 560ms! A 480ms boost of speed! So... long story short: parse the input! 5 1 9 14 15 1 11 12 13 10 15 Right answer is 3, but some algorithmes may give answer 2 for this test. P.S. I had this mistake:( P.P.S. Sorry, for my poor English... Thank you! This test helped me to fix WA6 Edited by author 10.07.2019 16:23 WA14(( No ideas... I tried any tests my brain could imagine. Can anybody help, plz? Hello, I can help you if want. If you give me your email I write you what I made to got AC from WA14.Sorry for bag english Edited by author 08.07.2019 19:37 I have try many of my tests, but I don't know what is wrong in my code. What is test #2, please? Try this one: INPUT 10 1 1 10 100 200 400 900 8100 45 285 456 2119 456 2120 456 3456 456 4080 456 4081 OUTPUT 1 No solution 2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222 9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999 14667777 No solution 1334444444444444444444444444444444444445555555555555555555555555555555555555555555555555555555555555 2677777777777777777777777788888888888888888888888888888888888 888999999999999999999999999999999999999999999999999 No solution Thank you for your test data! Thks you bruh. ths s1 and s2 hack me ->(456 2120) Me too. I try the Special test but it's wrong #2 test still. The #2 test is 100 100 ,or others which the length is 100. Why does this give runtime error #8 . n = int(raw_input()) k = int(raw_input()) dp = [[-1 for x in xrange(15)]for y in xrange(1910)] def solve(index,prev) : if(index > n ) : return 1 if(dp[index][prev] != -1) : return dp[index][prev] res = 0 start = 0 if(index == 1) : start = 1 for i in xrange(start,k) : if(prev == 0 and i == 0) : continue res = res + solve(index+1,i) dp[index][prev] = res ; return res print solve(1,0) Same for me, solution is python3. You have to check for recursion depth exceeded. Do it iterative. var str: string; i,kol,n,pol: integer; begin readln(n); pol:=1; kol:=0; for i:=1 to n do begin readln(str); if (str='Alice')or(str='Ariel')or(str='Aurora')or(str='Phil')or(str='Peter')or(str='Olaf')or(str='Phoebus')or(str='Ralph')or(str='Robin') then begin kol:=kol+abs(pol-1);pol:=1; end else if (str='Bembe')or(str='Belle')or(str='Bolt')or(str='Mulan')or(str='Mowgli')or(str='Mickey')or(str='Silver')or(str='Simba')or(str='Stitch') then begin kol:=kol+abs(pol-2);pol:=2; end else if (str='Dumbo')or(str='Genie')or(str='Jiminy')or(str='Kuzko')or(str='Kida')or(str='Kenai')or(str='Tarzan')or(str='Tiana')or(str='Winnie') then begin kol:=kol+abs(pol-3);pol:=3; end; end; write(kol); end. Edited by author 17.11.2016 23:36 Edited by author 17.11.2016 23:36 Check names carefully. For me it was a type mistake in "Mickey" а все моя ошибка написал "Bembe" вместо "Bambi" input: 6 5 6 4 2 1 0 6 1 5 3 0 6 0 6 output: 2 6 Why the second difference is 1.937 and no 2.000? input: 1 'a-z' like 'a-z' output: YES Edited by author 03.07.2019 23:01 Edited by author 03.07.2019 23:01 Hi, I have tried like million times different combinations, and it always gives wrong answer, always on 6. case. Does anyone have 6. case? Does any anyone have any idea what kind of strings/patterns are in 6. case? Thanks in advance In test 6 there are several consecutive '%' chars in the pattern. I got TLE, then replaced "%%" with "%" and passed. I'm guessing you can get WA on test 6 if you're not matching the empty string with "%". Very easy problem, not harder than Pineapple... Why so few people solved it??? Binary search can apply not more 120 people! What does it mean - not more than 120 people??? Pineapple was solved by about 300 authors! This is my prognoze (bookmaker). To solve this problem we must know two things: 1) 3d geometry and volumes; 2) binary search after 1 is implemented. So we divide 300 by 2 and have ~120-150. P.S. The problem has also very difficult component: 3) precision question and this is why so many people can't it solve and I am too. AC!!!! What does phrase W equals exactly 500 mean? |W-500|<eps and eps=10^-16? answer: if (W(x1)<=500)and (W(x2)>=500)) and |x1-x2|<0.5*0.000001 then ans:=round((x1+x2)/2). P.S.2: Tricky moments: 1)next cut must be measured from previous rounded integer value; 2) |x1-x2|<0.00000001 ! 0.0000001 is too small Edited by author 28.10.2007 11:25 Binnary search must be applied in integers. Also there is one trick in the statement: "...at which a cut should be made so that the weight of the NEXT piece be exactly 500 grams." So we must add not just 500gramms each time, but the mass of cutted part (some more or less then 500) add 500 and search. This was a reason of my WAs. I've done binsearch with reals and easily got AC. What concerns 500-gramm pieces - of course, we should measure mass from previous REAL cut, but not virtual and exactly-calculated - it is quite clear from the statement and ordinal logic... Edited by author 28.10.2007 15:38 Logic for integer rounded previous bound! This is realy made bound and exists but REAL cut is virtual! Question It is said that the machine which cuttes uses micrometer scale. So it can cut piece only in places with coordinates which are integer micrometers value. But after that it is said that a coordiante of current cut is ROUNDED to micrometers. What does that mean? The places where we can cut have integer micrometers value coordinats or the answers are integer micrometers value but we can cut at any position? Yes, places where we can cut have integer coordinates. So, mass may not equal to 500 grams, and you should choose such integer place for a cut to make it as close to 500 grams as possible. thanks a lot Sergey, you are wrong if you understand statematn at first time as autors it is not mean that statement is absolutely right and is not ambigious But I've read russian version of the problem and didn't find any ambiguity in it! It is almost equal to the english version of the statement. Where is ambiguity? Ambiguity is absent but absent also care about solvers, many mathematical and computing unimportant troubles precence. Next very easy but strangely seldom solved-1566: post office envelops. I solved it during 1 hour as problem 2 level of second division of TopCoders. Only two different geometric situations, float considaration without integer arithmetic and only 27 AC. try this: 8 6 7 9 13 18 24 31 50 expected: 0 8 6 7 9 13 18 24 31 50 My output : 4 expected: 0(How) 8 6 7 9 13 18 24 31 50 (18+6+24+31)-(50+7+13+9)=0 1) 0 2 4 1 2 Ans: 47.123889803847 2) 2 1 3 2 10 Ans: 309.510306200510 3) 15000 1 15000 1 15000 Ans: 1137333508.786799192429 One of my AC solution get AC, but on this test get answer "NO". (Correct answer is "YES"). 4 2 -30000 -30000 30000 -30000 30000 30000 -30000 30000 1 3 4 2 Don't forget about long long int! |
|