Common Board| Show all threads Hide all threads Show all messages Hide all messages | | AC (Pascal) | ArcKontyR | 1001. Reverse Root | 9 Jun 2017 11:40 | 1 | var a:array [1..200000] of int64; n,i: integer; begin while not seekeof do begin inc(i); read(a[i]); end; for n:=i downto 1 do begin writeln(sqrt(a[n]):4:4); end; end. I copied the solution from the other guy p.s. Sorry man, i dont know your nickname Edited by author 09.06.2017 11:43 | | AC (Pascal) | ArcKontyR | 1880. Psych Up's Eigenvalues | 9 Jun 2017 11:20 | 1 | var i,j,n,n#,n2,a,m:integer; l:array[#..400#,#..2] of longint; begin read(n); for i:=# to n do read(l[i,#]); read(n1); for i:=# to n# do begin read(a); for j:=# to 400# do if l[j,#]=a then l[j,2]+=#; end; read(n2); for i:=# to n2 do begin read(a); for j:=# to 400# do if l[j,#]=a then l[j,2]+=#; end; for i:=# to 400# do if l[i,2]=2 then m:=m+#; writeln(m); end. Where is # change it with 1 | | C# solution | InDevRus | 1586. Threeprime Numbers | 9 Jun 2017 07:03 | 1 | using System; using System.Collections.Generic; using System.Linq; namespace ThreeprimeNumbers { public static class IntExtensions { public static bool IsPrime(this int number) { for (var divisor = 2; divisor < number; divisor++) if (number % divisor == 0) return false; return true; } } internal static class Solver { private static Func<IEnumerable<int>> ThreeDigitPrimeNumbers = () => Enumerable.Range(100, 900).Where(number => number.IsPrime()); private static Dictionary<int, IEnumerable<int>> PrefixCorrespondance(IEnumerable<int> primeNumbers) { return primeNumbers .GroupBy(number => number / 10) .ToDictionary(group => group.Key, group => group.Select(item => item)); } internal static long Solve(int digitCount) { var table = new long[digitCount - 2, 90]; var prefixes = PrefixCorrespondance(ThreeDigitPrimeNumbers()); for (var counter = 10; counter < 100; counter++) table[0, counter - 10] = (prefixes.TryGetValue(counter, out var collection)) ? collection.Count() : 0; for (var counter = 1; counter <= digitCount - 3; counter++) foreach (var pair in prefixes) foreach (var primeNumber in pair.Value) { var suffix = primeNumber % 100 - 10; table[counter, pair.Key - 10] += (suffix < 0) ? 0 : table[counter - 1, suffix]; table[counter, pair.Key - 10] %= 1000000009; } long sum = 0; for (var counter = 0; counter < 90; counter++) sum = (sum + table[digitCount - 3, counter]) % 1000000009; return sum; } public static void Main() { int.TryParse(Console.ReadLine(), out int digitCount); Console.Write(Solve(digitCount)); } } } | | How to solve? | kilik | 1621. Definite Integral | 9 Jun 2017 04:40 | 2 | I use ferrari method to find roots. Then i got next equation 1/((x-a)*(x-b)*(x-c)*(x-d)), where a,b,c,d -roots of equation. How to calculate such an integral??? If someone can answer here or kilik94@yandex.ru, i would be very grateful! i'm not exactly sure of the solution but i think you could use rezidue theorem and solve the complex integral | | What is TEST #2 | Manoj Pathak | 1197. Lonesome Knight | 9 Jun 2017 04:18 | 1 | What is the test data for Test#2? | | WA1 i dont understand why (golang) | Khinel | 1197. Lonesome Knight | 9 Jun 2017 00:25 | 2 | package main import ( "bufio" "os" "strconv" "fmt" "strings" ) func main() { reader := bufio.NewReader(os.Stdin) firstLine, _ := reader.ReadString('\n') count, _ := strconv.Atoi(strings.Trim(firstLine, "\n")) result := make([]int, count) for i := 0; i < count; i++ { position, _ := reader.ReadString('\n') result[i] = countFieldsUnderAttack(position) } for _, val := range result { fmt.Println(val) } } func countFieldsUnderAttack(position string) int { result := 0 var positionInts [2]int positionInts[0] = int(position[0]) - int('a') + 1 positionInts[1] = int(position[1]) - int('1') + 1 moves := [8][2]int{ {1, 2}, {2, 1}, {-1, -2}, {-2, -1}, {-1, 2}, {2, -1}, {1, -2}, {-2, 1}, } for _, move := range moves { if move[0] + positionInts[0] > 0 && move[0] + positionInts[0] <= 8 { if move[1] + positionInts[1] > 0 && move[1] + positionInts[1] <= 8 { result++ } } } return result } Edited by author 08.06.2017 23:12 Nevermind. Implemented reading input with bufio scanner and it worked. It seems that i dont understand go reader. | | What's wrong? c++, | VNeo | 1068. Sum | 8 Jun 2017 15:18 | 2 | #include <iostream> using namespace std; int main() { int a,b; cin >>a; if (a>=1){ for (int i=1;i<=a;i++){ b=b+i; } } else if (a<1){ for (int i=1;i>=a;i--){ b=b+i; } } cout<<b; } i tested with test case #1 it work, but after submit the judge says wrong answer test 1, why? b initial value is? Do you use gcc? Probably "-Wuninitialized" option can help. | | Anyone WA @ 2. | 198808xc | 1518. Jedi Riddle 3 | 8 Jun 2017 12:41 | 2 | Make sure that: Ki (the second input line) is given in reverse order: eg. Kn, K(n-1), ... K2, K1. But, Ci (the third input line) is not: eg. C1, C2, ..., Cn. In the sample test, this will not make you sence... This is not declared in statement. Admin: will you add this? Edited by author 02.10.2010 21:20 Edited by author 02.10.2010 21:20 No, Ki are given in the correct order. | | C++ TLE hint | Alexey | 2104. Game with a Strip | 8 Jun 2017 01:08 | 1 | | | how to correct this error | ANIKET VISHAL | 1000. A+B Problem | 7 Jun 2017 14:37 | 3 | 8m3edk-w4h74s:1:9: fatal error: 'iostream.h' file not found #include<iostream.h> ^ 1 error generated. #include <iostream> Also better use not iostream, but rather STDIO. Just because? My opinion: C++ streams and C printf/scanf are equal. For GCC compiler, "std::ios::sync_with_stdio(false);" method call is required at main() very beginning. Significant input speed-up can be reached by using "getchar()" and/or "read()" functions and manual string->int conversion. This way is tricky, dangerous, I haven't seen task requires it. Edited by author 07.06.2017 14:49 | | Wrong answer test 1 | Alexey | 2021. Scarily interesting! | 7 Jun 2017 10:21 | 1 | Is first test from problem description? I can't find any issue | | Minimum vertex cover | Nikita Mogilevets | 1109. Conference | 5 Jun 2017 00:16 | 2 | Find maximal matching using Kuhn algo. Then greedily add missing connections. That is slow way. My C++ solution without any STL use runs in 230-240 ms. I found how to speed it up. Just use any stupid greedy algorithm to build some initial matching. After that apply Kuhn algo. Running time dramatically dropped to 31 ms in my case. Edited by author 05.06.2017 00:17 | | What is wrong? / WA#1 | Segrey_Shustov_rus | 1020. Rope | 4 Jun 2017 19:47 | 3 | #include <iostream> #include <iomanip> #include <cmath> using std::cin; using std::cout; using std::endl; using std::setprecision; using std::fixed; int main() { int n; double r,s=0,x,y,x0,y0,xn,yn; cin >> n >> r; if (n==1) { cin >> x >> y; } if (n>1) {
cin >> x >> y; for (int i=1;i<=n-1;i++) { cin >> x0 >> y0; s=s+sqrt((x0-x)*(x0-x)+(y0-y)*(y0-y)); x=x0;y=y0; } s=s+sqrt((xn-x)*(xn-x)+(yn-y)*(yn-y)); } s=s+2*3.1415*r; cout << fixed << setprecision(2) << s << endl; return 0; } DEV-C++ 5.11 Edited by author 04.06.2017 12:53 Thank you. I feel very sorry for such a stupid mistake... | | how to slove this ?? | shweta | 1208. Legendary Teams Contest | 4 Jun 2017 16:58 | 3 | Lamest O(2^K) is enough here. Act greedy. At each iteration select such team X, that if X in contest, then the number of teams can't attend contest is minimal. Remove such teams that have common members with X from the list. | | O(N^3) if well implemented is AC in less than 15 ms | Nikita Mogilevets | 1205. By the Underground or by Foot? | 4 Jun 2017 00:17 | 1 | | | Wa #13 | liudy | 2099. Space Invader | 3 Jun 2017 17:53 | 2 | Wa #13 liudy 13 Aug 2016 08:45 Can someone tell me what the test#13 example please? Something like AB and CD are orthogonal and complanar and there is no right such point E, that E lies on AB-line, E lies on CD line and the angle AED is ninety degrees. | | Idea O(N) | __Andrewy__ | 1135. Recruits | 3 Jun 2017 15:18 | 6 | Я долго бился с этой проблемой несмотря на то,что сложность <200. Я пытался решить с помощью ДП,но там очень много случаев и сложная реализация. Задачу можно решить логически: во-первых,первые символы "<" и последние символы ">" ни на что не влияют,поэтому удалим их; во-вторых,если слева есть хоть один ">",то он в ЛЮБОМ случае будет меняться с КАЖДЫМ "<" РОВНО один раз(если "<" существует). Т.е. нас не интересует конструкция строки. Нас интересуют числа Z[1],E[1],Z[2],E[2],...Z[p],E[p],где Z[i] -количество ">" в последовательности 00000000...00000,а E[i]- количество "<" в последовательности 11111....11111111. Т.е. нашу строку делаем в виде 00...0011..1100..0011..11........00..0011..11,где P чередований (я ">" заменил на "0",а "<" на "1") . Тогда ответ есть Z[1]*(E[1]+...E[p])+Z[2]*(E[2]+..+E[p])+...+Z[p]*E[p]. Сумму можно посчитать через частичные с помощью ДП. Асимптотика O(N). Imho, it can be solved by easier way. Let's create the array, where put 0 instead of '<' and 1 instead of '>'. Then answer is number of swaps in bubblesorting of this array. I went exactly this way and my solution looks very easy! >><<>< 110010 | counter = 0 Now we go from the right and move every 1 all the way to the right and count the moves (we don't need to actually move anything but you can see everything better this way) 110001 | counter = 1[4->5] 100011 | counter = 1 + 3[1->4] 000111 | counter = 1 + 3 + 3[0->3] = 7 I got AC with this O(n) Thank all of you) Very helpful! Get my AC using this solution Moving? Overkill. Just count how many inversions are there. I don't remember exactly, which symbol, '<' or '>', should be considered as 1 and which as 0. Don't even try to memorize the sequence. Just have a counter and increment it each time when encountered 1 and add counter value to answer each time when encountered 0. | | If you want a solution | Nikita Mogilevets | 1303. Minimal Coverage | 1 Jun 2017 11:37 | 1 | The problem is quite evil. The problem is actually very easy. It is hard to understand that the problem is that easy. Possible solution. First , eliminate all such segments I=[l;r], that l>M or r<0, because of such I's can't appear in the answer. Second, build your dp[]. Your dp[x] contains rightmost right end of all such segments [l;r], that l<=x. Finally, just start from segment whose right end is dp[0], jump to a segment whose right end is dp[dp[0]] and so on. How to build dp[x]? I have used an additional array right_end[y]. Where right_end[y] is the right end of a segment with maximal length from all segments whose left end is y. dp[x] =max(dp[x-1], right_end[x]). | | What does it mean? | nick nikuradze | 2100. Wedding Dinner | 31 May 2017 23:04 | 4 | What does it mean? Runtime error (access violation) This is my code on c++ #include <iostream> using namespace std; int n,ans; string s; int main() { cin>>n; ans=n+2; for(int i=0; i<n; i++) { cin>>s; for(int j=0; j<s.size()-3; j++) { if(s[j]=='+' && s[j+1]=='o' && s[j+2]=='n' && s[j+3]=='e') { ans++; break; } } } if(ans==13) ans++; cout<<100*ans; return 0; } Edited by author 31.05.2017 21:40 for(int j=0; j<(int) s.size()-3; j++)
Edited by author 31.05.2017 23:05 Edited by author 31.05.2017 23:05 The problem is "s. size() -3". The type of s. size() is SIZE_T. It is UNSIGNED. So, if s. length <=2,then SIZE_T overflows. The result is a HUGE number. And j goes out of range. "Access violation" means that you are trying to access some memory you are NOT SUPPOSED to access. Edited by author 31.05.2017 23:04 | | Why AC with C++11 and TLE with C++ | LastOne | 1613. For Fans of Statistics | 31 May 2017 17:52 | 2 | Your question is incorrect without code. In C++ 11, there are a lot of new features. Maybe just performance improvement of C++11 over earlier versions gives you AC. Look for example for string class. In C++98, strings are much slower, than modern strings. Your AC code runs in 800ms. Mine just in 240. http://acm.timus.ru/status.aspx?space=1&num=1613&author=201928You can made a lot of optimizations. After those optimizations, you will get no TLE on G++4.9. |
|
|