Общий форум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 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. 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]; 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"); } } 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 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 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 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 Could you please show your solution or hint? cost, fun1, fun2 = map(int,input().split()) fri, flat2 = [], [] for i in range(int(input())): fri.append(list(map(int,input().split())))
temp1, temp2 = [-1,-1], [-1, -1, -1] #веселье, квартрира, сосед for i in range(int(input())) : a, b, c = map(int,input().split()) if a == 2 : flat2.append([b,c,i+1]) # стоимость, веселье, номер if fun1 + c > temp1[0] and cost >= b : temp1 = [fun1+c, i+1]
for i in range(len(flat2)) : b, c, k = flat2[i][0], flat2[i][1], flat2[i][2] for j in range(len(fri)) : if fri[j][0] >= b/2 and cost >= b/2 and fun2+fri[j][1]+c > temp2[0] : temp2 = [fun2+fri[j][1]+c, j+1, k] if temp1[0] == -1 and temp2[0] == -1 : print('Forget about apartments. Live in the dormitory.') elif temp1[0] > temp2[0] : print('You should rent the apartment #'+str(temp1[1])+ ' alone.') else : print('You should rent the apartment #'+str(temp2[2])+' with the friend #'+str(temp2[1])+'.') Edited by author 16.09.2016 21:53 fun2 is when you live alone, so you can't add fun2 when living with a friend hi, this is O(1) complexity problem, you might want to decrease the Difficulty i guess to others: if you have found an extremum skip next point That's what I thought too ... the difficulty could be decreased by half at least. Maybe even more. AC in 0.015 is possible without any precalculations. Make a function that returns the quiet days until day N The answer is F(r) - F(l). The is a special case if l has to be counted - that happens if F(l) != F(l-1) (in other words F(l) is part of the sequence we are looking for) If l=1, just return F(r) The implementation of F(n) can be simple if you find the right approach. It's simple to count how many days remain in the sequence after eliminating each 2nd, then each 3rd, and so on. Out of all shortest path I am finding min of maximum distance I have to travel for every level. #include<bits/stdc++.h> using namespace std; void bfs(int u,vector<int> &d,const vector<vector<int>> adj){ d[u] = 0; queue<int> q; q.push(u); while(!q.empty()){ int u = q.front(); q.pop(); for(auto v:adj[u]){ if(d[v]>d[u]+1){ d[v]=d[u]+1; q.push(v); } } } } int main(){ int n,m; cin>>n>>m; vector<vector<int>> adj(n); for(int i=0;i<m;i++){ int u,v; cin>>u>>v; adj[u-1].push_back(v-1); adj[v-1].push_back(u-1); } vector<int> ds(n,1e9),df(n,1e9),dr(n,1e9); int s,f,r; cin>>s>>f>>r; s--,f--,r--; bfs(s,ds,adj); bfs(f,df,adj); bfs(r,dr,adj); vector<vector<int>> l(ds[f]+1); for(int i=0;i<n;i++){ if(ds[i]+df[i]==ds[f]){ l[ds[i]].push_back(i); } } int ans = INT_MAX; for(int i=0;i<=ds[f];i++){ int a = INT_MIN; for(auto x: l[i]){ a = max(a,dr[x]); } ans = min(a,ans); } cout<<ans; return 0; } This is wrong because you're assuming that the answer is the minimum distance to the robbers in its unique optimal path, which is not always true. Edited by author 17.08.2022 04:41 Edited by author 17.08.2022 04:41 Consider this test: 9 12 1 2 1 3 2 4 2 5 3 6 3 7 4 6 4 9 5 6 6 8 7 8 7 9 1 9 6 Correct answer: 1 (shortest path is either 1-2-4-9 or 1-3-7-9, so robbers can move 6-4 or 6-3) Just think of an increasing sequence. The program caculates n+1 times for an increasing sequence with n elements. And then divide it into two subsequences. One is the leftmost element, and anthoer is the left elements. It ends at the length of sequence is 2. Thus, the sum is (n+1) + n + (n-1) + ... + 3 = (n+4)(n-1)/2 = (n*n + 3*n - 4)/2. So output 1 to n is ok. union message { char bytes[4]; unsigned value; void reverse() { swap(bytes[0], bytes[3]); swap(bytes[1], bytes[2]); } }; Wow! That's unexpected =) Consider the case in which n < i, j That helped me to get AC Is the first test from conditions? If answer is "yes", then why the system say "WA1"? The program works correctly on my computer. Maybe, I misunderstood something important, and my output has wrong format? Help me, please. Edited by author 05.01.2013 15:42 Use "read" instead of "readln" Thank you! I had a very similar problem - WA1 ... each test I could think of was working correctly. Finally I changed the new line from \r\n to \n - that fixed the problem. Prime Divisor of b - Prime Divisor of a lol.hi :)
can be even simpler and faster - Prime Divisors of (b / a) You must find the first team that may go final if q wil be q+1. You mustn't output the team after q th finalist. Example: 2012 6 3 SPBU ITMO # 1 (finalist) URAL SU # 1 (finalist) SPBU ITMO # 2 SARATOV SU # 3 (finalist) URAL SU # 2 (not finalist !!!) SPBU SU # 1 (answer) Edited by author 03.12.2011 13:18 Edited by author 26.11.2019 02:40 And one more thing to look for - after the number is removed, make sure any white spaces are trimmed at the end. i.e. "SPBU SU " should be "SPBU SU" |
|