Common Board Edited by author 05.06.2020 17:42 I can solve it by breadth-first search with Execution time:0.218, but how to solve it with Execution time:0.015 or 0.031??? I have no idea about it. Give me please idea or algorithm's name to solve it so fast. thank you! [code deleted] his work time 0.31 Edited by moderator 19.11.2019 23:11 You can solve fast using BFS)) [code deleted] work timeL 0.015 Edited by author 20.12.2018 15:38 Edited by moderator 19.11.2019 23:11 Give tests, please!! try: 2 4 satisfied 5 hungry You are so awesome, that I want to become your girlfriend, pleeeeease marry me!!!!!!!!!!!!!! Прошу помочь. Написал алгоритм на питоне, все придуманные мной примеры работают, однако шестой тест неумолим... Подскажите, где ошибка? Код прилагаю string = input() find = 'Sandro' lst = [] string = ' ' + string + ' ' def counter(indexInFind, indexInString): global string global find summ = 0 index = 0 temp='' for i in range(indexInString - indexInFind, indexInString - indexInFind + 6): if string[i] == ' ': return # if string[i] != find[index]: summ += 5 index += 1 temp += string[i] return summ if temp.find('S') != -1 or temp.find('s') != -1 else summ+5 for i in range(len(string)): strfind = find.find(string[i]) if strfind != -1: lst.append(counter(strfind, i)) print(min(lst) if len(lst) != 0 else 35) Edited by author 19.12.2018 01:29 Edited by author 19.12.2018 01:29 Edited by author 19.12.2018 01:31 a=int(input()) b=int(input()) if (a%2) == 0 or (b%2) == 1: print('yes') else: print('no') помогите найти ошибку. вроде ответы правильные выдаёт using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp3 { class Program { static void Main(string[] args) { string[] a = Console.ReadLine().Split(); int b = Convert.ToInt32(a[0]); int c = Convert.ToInt32(a[1]); int d = 0; string[] e = Console.ReadLine().Split(); for (int f = 0; f < c; f++ ) { d = d + Convert.ToInt32(e[f]); } int g = d - b * c; if (g < 0) { g = 0; } Console.WriteLine(g); Console.ReadLine(); } } } Am I stupid or what? code seems to be working var x,a,b:integer; function sum(x:integer): INTEGER; var s:integer; begin while x>0 do begin s:=s+x mod 10; x:=x div 10; end; sum:=s; end; begin read (x); a:=x div 1000; b:=x mod 1000; if (sum(a)=sum(b+1)) or (sum(a)=sum(b-1)) then writeln ('Yes') else writeln ('No'); end. Pay attention to inc and dec in your code. You should do first x+1 and x-1. I hope you understand me Can someone give me test #18??? Or give me some tests and answers??? For: 75000000000000000 50000000000000000 25000000000000000 answer is 2 (1 ≤ x1, x2, x3 ≤ 10^18) Try to use int64 Thanks, but i have already use int64/ but i dont know where's my error... :( I have submitted it more than one times with int64, but again and again I got WA on test19, however, same source code in Java using BigInteger was accepted at once. 45 1 12 You can have problems with sorting your array it was helped me. Good luck, bro! Edited by author 13.12.2018 21:43 Edited by author 13.12.2018 21:43 I didn't find a mistake in my program. And what is the test #19? I'am confused( 45 1 12 it was helped me. Good luck, bro! tovars,prices,recomendations= [],[],[] for i in range(6): name = input() tovar = input() price = int(input()) if tovar in tovars: if prices[tovars.index(tovar)] > price: prices[tovars.index(tovar)] = price recomendations[tovars.index(tovar)] +=1 else: tovars.append(tovar) prices.append(price) recomendations.append(1) if recomendations.count(max(recomendations)) == 1: print(tovars[recomendations.index(max(recomendations))]) else: ans = [] ans1 = [] l = len(tovars) mm = max(recomendations) for i in range(l): if recomendations[i] == mm: ans.append(tovars[i]) ans1.append(prices[i]) print(ans[ans1.index(min(ans1))]) Could you please add Common Lisp as a language? SBCL is the most popular, and most performant, implementation of Common Lisp, and has been for some time (forked from CMUCL nearly 20 years ago)! It is also mostly maintained by Stas Boukarev. It has static typing, and it would be a beautiful language to solve Timus problems in. Common Lisp has been around for a very long time and its ANSI Standard has been the same for quite a number of years, so it is possible that there would not need to be many updates after it is added once. Adding the SBCL implementation as a supported language would be greatly appreciated by me and the Common Lisp community to be able to solve the amazing problems on this website with this very performant meta programming language. While attempting to get SBCL added, this repo could be used for reference -- https://github.com/optimisticlisper I really hope you will consider it. #include<stdio.h> #include<math.h> int main() { int n;
printf("%d\n",scanf("%d",&n)*n*scanf("%d",&n)*n*scanf("%d",&n)*n*2); } you write so complex, the answer is N*A*B*2 why so complex man!! Should it work at all? Isn't it unspecified behavior - n is modified 3 times in the same expression? Brother, you should solve it step by step!Don't do all things in printf function.In this way u can easily find you bug! You can follow this method n*a*b*2 At first,I got wa on test1,like many other authors.But later,I found it! All in one sentence,test the data below: 1 inputon Hello, The answer is YES and my program out puts YES, but I get WA1. Can you please help me what I am doing wrong. It passes all of my tests but gets wa 1. I'm confused too, maybe there are some design errors, like 'Yes' or 'yes'when you have to use "YES\n" I have the same problem and the reason of problem was: character '\r' at the end of test inputs string (at my PC i use Linux and there is no such problem). Then I start to check input for '\r' character and this code was accepted! it's good test. Thank you. Create struct: struct Animal which has: - ID // ID of hero - name // name of animal (char *) (cin.getline) (cin.ignore()) - strength(int) // power of animal - frequency // number of hits in one iteration - HP // amount of life Your task is to show animal which won most rounds in the game. Input: n (how many animals) [2 <= n <= 10] n-times: ID name strength frequency goals HP goals Output: winner with amount of victory. Example: Input: 10 1 Lion John 30 2 100 // (0 1 0 0 1 0 1 0 0) 3 victory 2 Hen Rebecca 60 1 200 // (1 1 1 0 1 0 1 0 1) 6 victory 3 Tiger Alex 40 2 100 // (1 0 0 0 1 0 1 0 1) 4 victory 4 Buffalo James 40 3 100 // (1 1 1 0 1 0 1 0 1) 6 victory 5 Elephant Jack 50 1 300 // (1 1 1 1 1 0 1 0 1) 7 victory 6 Rhino Michael 30 1 200 // (1 0 0 0 0 0 1 0 0) 2 victory 7 Snake Oz 50 2 400 // (1 1 1 1 1 1 1 1 1) 9 victory 8 Cow Bettie 40 1 100 // (0 0 0 0 0 0 0 0 0) 0 victory 9 Crocodile Nick 20 3 500 // (1 1 1 1 1 1 0 1 1) 8 victory 10 Bear Drake 40 2 150 // (1 1 1 1 0 1 0 1 0) 6 victory Output : 7 Snake Oz 50 2 400 9 victory use "long double" and to avoid rounding when you print the result, use cout << fixed <<setprecision(0)<< result << endl; Can you explain us why long double accepted and why double get WA13 ? Edited by author 21.01.2019 19:40 If it is a real tree, why after N lines, describing conviviality ratings of employees, we have not simply (N - 1) lines, describing supervisor relations? Does such input format mean that some employees may have more than one supervisors? Edited by author 21.06.2012 18:08 Input contains only one tree (not forest) so don't worry about this ! Why do I memory limit exceeded even if I have use pointer? Here is my code: const mn=6000; inf=-100000000; type rec=record father:integer; num:integer; child:array[1..mn]of ^integer; end; var value:array[1..mn]of ^integer; f:array[1..mn,1..2]of ^longint; t:array[1..mn]of ^rec; n,i,a,b,root:integer; ans:longint; function max(a,b:longint):longint; begin if a>b then exit(a) else exit(b); end; function dp(root,lab:integer):longint; var i:integer; begin if root=0 then exit(0); if f[root,lab]^>inf then exit(f[root,lab]^); if lab=1 then begin f[root,lab]^:=value[root]^; for i:=1 to t[root]^.num do inc(f[root,1]^,dp(t[root]^.child[i]^,2)); end else begin f[root,lab]^:=0; for i:=1 to t[root]^.num do inc(f[root,2]^,max(dp(t[root]^.child[i]^,1),dp(t[root]^.child[i]^,2))); end; exit(f[root,lab]^); end; begin readln(n); for i:=1 to n do begin new(value[i]); new(t[i]); new(f[i,1]); new(f[i,2]); readln(value[i]^); end; while not eof do begin readln(a,b); if(a=0)and(b=0)then break; t[a]^.father:=b; inc(t[b]^.num); new(t[b]^.child[t[b]^.num]); t[b]^.child[t[b]^.num]^:=a; end; for i:=1 to n do if t[i]^.father=0 then begin root:=i; break; end; for i:=1 to n do begin f[i,1]^:=inf; f[i,2]^:=inf; end; ans:=max(dp(root,1),dp(root,2)); writeln(ans); end. Who can HELP me? Edited by author 05.04.2010 16:57 because u r using much memory.. run it on ideone.. u will come to know This problem is too simple than you think :) Edited by author 10.12.2018 17:39 Some test cases that helped me: 6 4 001000 100001 000100 000010 010000 100100 100000 111000 100000 ans: 111111 6 4 010000 100000 001000 100001 100000 111000 000100 000001 100000 ans: 111001 6 4 100000 111000 010000 100000 001000 100001 000100 000001 000000 ans: 000000 6 4 111100 111000 111110 100000 000000 100001 111111 000001 010100 ans: 110101 6 4 111000 101000 111100 111000 111110 100000 111111 000001 011100 ans: 011100 6 0 010100 ans: 010100 |
|