Общий форумprogram text; {$APPTYPE CONSOLE} var n,k,i,j,n1,n2,col,lastlen:integer; num1,num2:array[0..1000001] of byte; t1,t2:longword; Procedure Add; var i,carry:integer; begin carry:=0; for i:=1 to high(num1) do begin carry:=carry+num1[i]+num2[i]; if carry>=10 then begin num1[i]:=carry-10; carry:=1; end else begin num1[i]:=carry; carry:=0; end; end; end; begin { TODO -oUser -cConsole Main : Insert code here } { Assign(input,'Input.txt'); reset(input); Assign(output,'output.txt'); rewrite(output); } fillchar(num1,sizeof(num1),0); fillchar(num2,sizeof(num2),0); readln(n); col:=0; k:=0; for i:=n downto 1 do begin readln(n1,n2); num1[i]:=n1; num2[i]:=n2; end; ADD; k:=high(num1); while num1[k]=0 do dec(k); if k=0 then writeln(0) else for i:=k downto 1 do write(num1[i]); end. I think you should be more careful when you read the task. Test 4 0 0 1 1 1 1 1 1 Answer 0222 And your program gives 222. Edited by author 06.09.2006 15:38 //but why me #include<bits/stdc++.h> using namespace std; int main() { long n,i,j=0; scanf("%ld",&n); int a[2000003],b=0; string s; n*=2; for(i=0;i<n;i++){ scanf("%d",&a[i]); } for(i=n-1;i>=0;i=i-2){ b=(b+a[i]+a[i-1]); s[j]=(b%10)+48; b=b/10; j++; } //if(b!=0){ //cout<<b; //} for(i=j-1;i>=0;i--){ printf("%c",s[i]); } } I have made the same mistake. Edited by author 30.07.2019 19:29 #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; int a; int b; long double c=0; for (unsigned int i = 0; i < n; i++) { cin >> a; cin >> b; if (i != 0 ) { c = c * 10 + a + b; } else c = a + b;
}
cout <<c<< endl; } 3 1 1 9 0 9 1 try this this test helped me My code's producing 300. It's right, isn't it? What is double mantissa size? About 17 decimal digits? What is required number size? About 1,000,000 digits? So, how your solution is supposed to work? //wa on test 2 .. whats the problem with my code #include<bits/stdc++.h> using namespace std; int main() { long n,i,j=0; cin>>n; int a[2000003],b=0; string s; n*=2; for(i=0;i<n;i++){ cin>>a[i]; } for(i=n-1;i>=0;i=i-2){ b=(b+a[i]+a[i-1]); s[j]=(b%10)+48; b=b/10; j++; } for(i=j-1;i>=0;i--){ cout<<s[i]; } } What is correct algorithm? My program that find 2 mins and print Math.Max(min1 + min2 - n, 0) don't pass test 13. Consider test 3 3 2 2 2 Your solution says that there is a person who knows three different dialects. But we can construct an example where it is not true: 1) first person knows dialects number 1 and 2 2) second knows 1 and 3 3) third knows 2 and 3 Do u give me ur wrong code? How did the thief steal the bicycle ?I'm not pretty sure. Is there some one telling me ? The thief steals the bicycle if he opens the lock, that is, if the code he tries is the same as the code for the lock. Test 1: Den's keys: 0001 0000 1st night 2nd night 3rd night 4th night ... ... ... All nights bike's key 0001 0000 0001 0000 - bad man 0000 0001 0003 0004 - result no no no no no Test 2: Den's keys: 0002 0001 1st night 2nd night 3rd night 4th night ... ... ... All nights bike's key 0002 0001 0002 0001 - bad man 0000 0001 0003 0004 - result no yes no no yes In the first test all nights result is "no". That why in the first test result is no. Thanks a lot for the explanation. Sorry for my bad English. I use int ch; while ((ch = System.in.read()) != -1) { // my solution System.out.print(<some char>); } System.out.println(); But I get WA #1 with or without last code line. I also used System.out.flush (without last line), but it do not help me. Use Scanner from utils,that's better and esier , than use System.in.read() Edited by author 24.06.2019 13:55 use 'long' instead of 'int' as accumulator hEdited by author 19.07.2019 12:15 Edited by author 19.07.2019 12:16 import math nm = input().split() n = int(nm[0]) m = int(nm[1]) res = set() result = [] for i in range(m): x = int(input()) if x not in res: res.add(x) result.append(x) answer = [] for i in res: answer.append(result.count(i)) while n - len(answer) > 0: answer.append(0) for i in answer: v = str(round(i*100/m, 2)) if v[-2] + v[-1] == '.0': print(str(round(i*100/m, 2)) + '0%') else: print(str(round(i*100/m, 2)) + '%')
Edited by author 24.02.2019 01:39 Edited by author 09.03.2019 03:19 n, m = [int(x) for x in input().split()] x = 0 k = [0]*(n) for i in range(m): x = int(input()) k[x-1] = k[x-1]+1 for u in range(n): print( "%.2f" % (k[u]*100/ m), "%", sep="" ) input: 10 5 4 4 2 1 1 4 0 4 3 0 10 4 10 output: 1 4 14 6 1 5 4 1 4 3 0 3 3 0 13 4 7 4 7 1 0 1 5 3 1 0 1 output: 1 3 #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. |
|