Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
easy bfs | 👑TIMOFEY👑 | 1419. Карта мира 40 островов | 1 янв 2023 18:40 | 1 |
|
Why I am getting TLE in c++ ? Please help. | Muhammad Abdullah | 1001. Обратный корень | 31 дек 2022 00:29 | 6 |
#include <bits/stdc++.h> using namespace std; int main(){ long long n, res; vector <long long> vt; while(cin>>n){ vt.push_back(n); } int len = vt.size();
for(int i = len-1; i >= 0; i--){ double n = sqrt(vt[i]); printf("%0.4lf\n", n); } return 0; } Edited by author 07.09.2019 11:05 Edited by author 07.09.2019 11:11 while(cin>>n) .... Its an infinite loop. My AC solution also used while (cin >> n) double instead of long long while declaring n and vector. |
Accepted 0.156 2 993 КБ | TakeOver | 1067. Структура папок | 29 дек 2022 02:14 | 3 |
Just used STL contaners such as std::map<std::string,T>, std::vector<T>. :) 33 lines of code. what is "T"? give please full description. I used a map and a set. My time was a little less than 2 times faster, and used a little more than 2 times more memory. struct dir { std::string name; std::map<std::string, dir*> children_items; std::set<std::string> children_names; }; The set gives you the sorted list. The map gives you instant access to a subdirectory of a given directory by name (taken from the set) Edited by author 29.12.2022 02:15 |
Such easy problem , A big Hint ! | XueMao | 1115. Корабли | 27 дек 2022 23:34 | 4 |
you can only use dfs , but don't forget to sort the team . When I use sorting as from short to long , I got TL , but when from long to short , only 0.02s ! I sort from long to short, but still Time Limited Exceeded. Can you tell me why? :) Edited by author 23.12.2018 21:36 Edited by author 23.12.2018 21:39 I was expecting TLE, because I use O(N^N), but in fact got AC in 0.015 I wonder if people who get TLE are doing something like O(N^N^N^π^e) lol |
Same code - AC on 1115, WA11 on 1394 | Hristo Nikolaev (B&W) | 1115. Корабли | 27 дек 2022 23:30 | 1 |
Apparently, this is a very complicated problem, but 1115 allows solutions with naive implementations. I almost used brute force here, with some little optimizations (like looking for solutions for the next few sums while working on the 'current' one). |
Why is my code in python language wrong? | Mayari Villalba | 1001. Обратный корень | 27 дек 2022 14:21 | 2 |
a=[int(i) for i in input().split()] for i in a[::-1]: print(f"{float(i)**0.5:.4f}") because u proggram should take more one string. But i too not lnow how solve this task Edited by author 27.12.2022 14:22 |
Some tests | andreyDagger | 1998. Старый падаван | 26 дек 2022 09:54 | 2 |
5 3 1 2 2 2 2 2 3 4 6 ans: 11 5 3 3 1 2 3 4 5 1 4 7 ans: 12 9 9 123 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ans: 9 Why does the last test have an answer 9? on 9th second he can't pick up the last stone, instead he drops all of them, so isn't the answer 27? |
How do you solve this problem ? | rohit | 1854. Переговоры с Парфией | 25 дек 2022 23:22 | 6 |
Some hints please. My algo takes too much time. You need factoring N by numbers 2..10^6. If after factoring N>1 and N not prime, then your N=p*q, where p and q - prime numbers. Edited by author 27.09.2011 16:46 most difficult case n=p*p, where p- is prime for it case quick _int64 sqrt(__int64 n) function is needed, in other cases there is a factor of n which is <1000000. svr what should be the output when n = p*p where p is prime ?? i guess just n ? becuase n is already odd and its the maximum ? Edited by author 19.01.2015 01:04 I just did straight forward factorization (with rho) of an input number and then divided it by primes that have an odd power in factorization. 0.31 ms, 1400 kb. Edited by author 08.07.2018 18:21 AC in 0.015 (in plain C) with something much simpler than RHO. - start factorizing the simplest way they teach you in the kindergarten - when the test reach large values, check if the reminder has a perfect square -- if so - return the square and count as it is a prime divisor ^2 (because even if it can be factorized, it will be an amount of multipliers ^2) -- if no - stop checking (because the reminders are obviously large prime values ^1 and can be ignored) - multiply all primes with even powers * primers with odd powers (n) >= 3 with power n-1 I bet it can be accepted in 0.001 if Intel C 7 was still a compiler option. |
I GET WA1!!!!! | Marian Darius | 1033. Лабиринт | 24 дек 2022 16:32 | 3 |
PLEASE TELL ME WHAT IS WRONG! I TRIED EVERYTHING!!! #include<stdio.h> #include<queue> using namespace std; struct Coord {int x,y;}; int a[40][40]; inline int number(int x,int y) { int nr=0; if(a[x+1][y]==-1) nr++; if(a[x-1][y]==-1) nr++; if(a[x][y+1]==-1) nr++; if(a[x][y-1]==-1) nr++; return nr; } Coord make(int a,int b) { Coord x; x.x=a;x.y=b; return x; } void lee(Coord s) { int x,y; queue<Coord> q; q.push(s); a[s.x][s.y]=1; while(!q.empty()) { x=q.front().x;y=q.front().y; if(a[x+1][y]==0) {a[x+1][y]=1;q.push(make(x+1,y));} if(a[x-1][y]==0) {a[x-1][y]=1;q.push(make(x-1,y));} if(a[x][y+1]==0) {a[x][y+1]=1;q.push(make(x,y+1));} if(a[x][y-1]==0) {a[x][y-1]=1;q.push(make(x,y-1));} q.pop(); } } int main() { int n,i,j;char ch; scanf("%d\n",&n); for(i=1;i<=n;i++,scanf("%c",&ch)) for(j=1;j<=n;j++) { scanf("%c",&ch); if(ch=='.') a[i][j]= 0; else a[i][j]=-1; } for(i=2;i<=n+1;i++) a[i][0]=a[0][i]=-1; for(i=0;i<n;i++) a[i][n+1]=a[n+1][i]=-1; lee(make(1,1)); lee(make(n,n)); int nr=0; for(i=1;i<=n;i++) for(j=1;j<=n;j++) if(a[i][j]==1) nr+=number(i,j); printf("%d\n",9*nr); return 0; } Is sample test case working for this program ? WA1 usually means the new lines ( \n ) or ( \r\n ) are not handled correctly. |
Admins, make it 3 ≤ N ≤ 333 | Hristo Nikolaev (B&W) | 1033. Лабиринт | 24 дек 2022 16:30 | 1 |
Or at least add another version of the problem with huge labyrinths. I had a lot of fun with this problem, and was surprised that a solution which is far from perfect can work instantly with input 200x200. |
if WA4 try this | skyhoop | 1033. Лабиринт | 24 дек 2022 16:19 | 5 |
Thanks!This really helps. Thx a lot! But I thought the end of the labyrinth must be reachable from the beginning... Thank you! I also gathered the impression that 1,1 is the entrance, and n,n is the exit ... Without this misunderstanding, I would have had AC from the very first attempt. Cheers! |
about TLE (spoilers) | Gerasimov Alexander Dmitrievich | 1915. Руины титанов: воссоздание былого | 23 дек 2022 01:32 | 2 |
In C#, I was getting TLE using LinkedList, so I rewrote everything using an array of 2*10^6 elements. It passed in 1.7s (thank god), but that's still very slow. How do people get times like 0.2s? It can be much faster if implemented in C/C++. (Edit: I just saw that you have submitted a faster solution in C++) A simple trick I used is to ignore 0 (copy the entire stack) if its elements are > 10^6 Edited by author 23.12.2022 01:43 |
Very very bad title | ucs6 | 1280. Topological Sorting | 22 дек 2022 19:15 | 3 |
Don't be trapped by the title of this problem...it would just make it more complicated I see no problem in the title. It's a very simple straight forward TOP_SORT problem. And I have seen some critical cases in other threads which cases would appear 'critical' if and only if any process other than simple top_sort is approached. I`d say don`t be trapped by the category of the problem. It says Graph Theory, but can be easily solved with other data structures. |
Accepted map<int, set<int> > + lower_bound 0.499 | nadinne | 1613. Для любителей статистики | 22 дек 2022 18:52 | 5 |
Edited by author 06.02.2016 13:30 Edited by author 06.02.2016 13:38 My result is 0.1 sec, 700 Kb memory usage. I used VS 2013 (probably its IO works quicker then gcc), C-style (printf/scanf) IO, sorted vector of pairs (count_of_passengers, city_number). Have a similar solution for Java: HashMap<Integer, TreeSet<Integer>> and floor/ceiling functions. I've got execution time: 0.998 it's kinda funny )) Edited by author 28.03.2019 12:57 I used the same approach - works much faster 0.218 make sure you are not making unintended copies of the set and use a reference - std::set<int>& current_set = m[x]; instead of std::set<int> current_set = m[x]; |
i got AC in C.. | Suparna | 1068. Сумма | 18 дек 2022 20:07 | 3 |
int num,n,i,sum=0; // read n;
//case 1 if(n>0){ for(i=1;i<=n;i++){ sum=sum+i; } printf("%d",sum); } //case 2 if(n<0){ for(i=(-1);i>=n;i--){ sum=sum+i; } sum=sum+1; printf("%d",sum); } //case 3 else if(n==0){ printf("1"); } } when n<0,then sum=sum+1; why you using sum=sum+1; #include<stdio.h> int main() { int num,n,i,sum=0; scanf("%d", &n); if(n>0){ for(i=1;i<=n;i++){ sum=sum+i; } printf("%d",sum); } if(n<0){ for(i=n;i<=1;i++){ sum=sum+i; }
printf("%d",sum); } else if(n==0){ printf("1"); } } |
Admins, please fix the tests. | Hristo Nikolaev (B&W) | 1517. Свобода выбора | 18 дек 2022 00:57 | 1 |
Using the same code, and only switching the order of the 2 input strings ... scanf("%s", strr); scanf("%s", strl); leads to WA5 switching the order (shouldn`t make any difference) scanf("%s", strl); scanf("%s", strr); and I get WA6 |
One more WA2, and none of the tests help | Hristo Nikolaev (B&W) | 1038. Проверка орфографии | 17 дек 2022 02:18 | 2 |
I tried everything suggested in the discussion. Each test works, but when I submit, I get WA2. Can you please add more tests? Strange ... and now I got AC without any change to the logic. Just made each char taken from getchar() processed immediately instead of filling an array and then processing the array. Both versions work equally well on my computer. I use VS 2022. And one more thing - absolutely the same way of reading the input and filling the array I initially had a WA2 with, worked perfectly for problem 1601. AntiCAPS. (Actually that's where I copied the functionality from before I start). I guess Admins should take a look at this. Edited by author 17.12.2022 02:22 |
To those who get WA#7 | vicproon | 1205. На метро или пешком? | 17 дек 2022 00:16 | 8 |
Looks like stations can overlap (have same coordinates) while not being connected with underground! What does this actually mean??? If coordinates are the same then travelling time is still 0. is not it? Even I found that footseed is 0.5 in test 7. But what then? It doesn't change my solution and i can not understand if it actually does... :( You are right, ori and dst stations can overlap connected stations. I think, not only stations can overlap but also original and destination points. Two below tests helped me to understand my mistake when I've received Runtime Error 7 and Wrong Answer 7: 1 100 4 1 1 2 2 3 3 2 2 2 1 3 4 4 2 0 0 1 1 3 3 answer: 0.0282843 4 1 2 4 3 1 100 3 1 1 2 2 3 3 2 1 3 2 1 3 0 0 1 1 1 1 answer: 0.000000 0 Edited by author 26.10.2018 16:55 Edited by author 26.10.2018 16:56 Got correct answers for both tests above (and for all others in other topics). Still WA7. To authors of the problem - burn in hell. try this one 1 100 5 0 0 1 0 9 0 9 9 10 10 1 2 1 3 2 4 0 0 10 10 the result should be 2.6346295 4 4 2 1 3 10 0 test is not correst, no destination point Edited by author 17.12.2022 00:16 Edited by author 17.12.2022 00:16 Edited by author 17.12.2022 00:17 |
TIMUS ID / Handle | Ashfak Hossain Evan | | 14 дек 2022 22:57 | 1 |
What is my timus handle ? in a place I give my username and they decline that and say that timus handle should be a number. What is my number? how can I find the ID? Edited by author 14.12.2022 22:58 |
bfs is not needed | vegetable | 1106. Две команды | 13 дек 2022 12:29 | 2 |
Could you please show your solution or hint? |