Общий форумI can't understand what do we need the plain coordinates for. Edited by author 20.12.2008 14:48 For nothing I think. I absolutely ignored coords, used standard Maxflow and got TLe13 because of 0.5 sec. Main point is speed. There are 2 different ways to solve this problem. The first one is to optimize one of the standard Maxflow algorithms to pass TL. The second one is to use the planarity of graph, design an algorithm that is asymptotically faster than the standard ones, and get AC with it. I wrote this problem one year before , with standart maxflow algorithm , and got AC during the contest. Exuse me!.Brilliant the problem, thank the authors. We build dual graph and use Dejkstra in it- O(nlog(n)). But computing dual graph is separated difficult problem from computational geometry connected with walking on grid with extacting faces. Now I am implementing this approach. In test 14 I have situation when starting from some edge and making maximal possible turn to left we don't return to starting edge. Is it possible in comlex geometry or bug in program. Edited by author 18.07.2009 11:05 I've implemented svr's approach and it seems to be the fastest one. I had a lot of problems with my program, but not on test 14 or 15. But I have overcome WA#16 when replaced atan2 with exact geometry. Found: test 14 contains edge with only one facet :) I also have implemented it. Dual graph making is not very easy. But strength (n*log(n)) of this method is great. I used set,vector and had not TL. Edited by author 19.12.2011 12:22 It's a great problem. I enjoyed solving it! DP on subsets + match in bigraph - was not hard to implement at all. Just nice step-by-step implementation! And what a great time! Only 0.031 ! It's really great!) Edited by author 30.06.2007 21:15 What is your complexity? Does your solution use (2^n) * (2^n) memory? Edited by author 10.07.2007 13:39 The complexity of my solution is approximately O((2^N)*(2^N)*N*N). More exactly it is O(Mk*N*N), where Mk = C(N,N-1)+C(N,N-2)*2^2+C(N,N-3)*2^3+...+C(N,2)*2^(N-2)+C(N,1)*2^(N-1) where C(N,M) - is the number of combinations :) I use as much as O((2^N)*(2^N)) memory. Good luck! Thank you for answer. I have tried to find algo with O( 2^n ) memory, but it seems, that there does not exist such "non factorial" algorithm :( So I have implemented O( (2^n)*(2^n)*n*n ) algorithm that uses O((2^n)*(2^n)) memory (asymptotic is correct). This algorithm does not use bipartite matching algo at all. AC in (0.015 :: 1 287 KB). UPD: Also I realized O((3^n)*n) algo with O((3^n)*n) memory which has taken AC in (0.031 :: 8 439 KB), but I was aware of low level optimization Edited by author 17.07.2007 15:58 It's easy to implement O(2^N) memory algo - just DP on subset of pupils that know those news, each bit 1 can spawn at most one more bit 1 if there is an edge, the set of transitions can be calculated at O(2^N * N^2) overall time (state with 2^P ones leads to at most 2^(N-P) ones and these transitions can be calculated by BFS - number_of_src_bit1 X number_of_dst_bit1) P.S: AC in 0.015 sec / 305Kb, 1st effort :) Edited by author 12.08.2008 02:14 There is 3^n * n^3 algo. For every mask check its sub masks (total 3^n checks). Every check - finding bipartite matching in graph. But a do it easy: for every 2^n masks generate all masks what we can achieve with recursive function. use state machine with char-by-char reading. We know last char and last state, so we can find next state. Brackets should be counting during reading. If we have '(', so we plus 1, ')' - minus 1. If brackets < 0 and state is some of arifmetic state - it's error. Here's the test that helped me 5 A AC B AC D TL 7 D TL 7 D TL 6 1 3 Thanks. It was really helpful. This is also my question answer plz! 1 Smmam WA 7 Answer: 1 1 so why when it is AC the minimum possible is still 0? explain clearly plz!!!! coz that solution may pass a new tests, so minimum possible is 0 If the solution pasts the 6-th case it is not necessary to be wrong. Edited by author 10.10.2009 15:41 Edited by author 10.10.2009 15:41 as i understood the minimal numbers of autors is not zero, when verdict is WA or ML or TL and the test is 7 when minimum possible is increased the maximum is increased too !? If the test is 7 - and if it fails, then obviously the code is wrong, that author won't get any mail for that case. Edited by author 10.10.2009 16:40 didn't understand. if test 7 fails, new verdict will be fail on 6 test. so it's new verdict Oh! :O I think you are right. User 2 sets : minUsers and maxUsers and be happy Thanks for the test. Edited by author 18.12.2011 17:05 I got a AC program from others and compare the ANSWER-nothing is wrong. So the ADMIN I need the TEST#1 please! It seems that the time limit for this problem is so tight, because I used heap + set and map and I got TLE. Does anybody have any suggestions? Edited by author 22.01.2009 17:08 I've used almost the same structures and AC. Try to optimize your program. Do you use scanf()/printf() for input/output? Thank for your Reply. Yeah, I used scanf/printf for IO. I think I should have reduce the number of maps in my code. I used following structures: map < string , int > city_to_index ;// locate the position of each city in the heap. map < string , string > where;// locate the city in where the billionaire is map < string , LL > how_much;// the amount of money each billionaire has map < string , int > answer;// the answers Do you have any idea to reduce them? One problem that I think that my cause TLE is that I built my heap in array and each time I update my heap I should have change the values in city_to_index. Maybe if I implement it with pointers would be better. I mean, it may be better to build the heap with pointers and for swapping the nodes their addresses in city_to_index remains unchanged. (map<string,node*> city_to_index) IT IS SOMEHOW COMPLICATED FOR ME TO IMPLEMENT IN THAT WAY, DO YOU HAVE ANOTHER IDEA? Edited by author 22.01.2009 19:23 You must before coding be sure in time and space limits of your algo. This is difficult but is core of programming skills. You take right general plan remove bags and get AC. Thanks for your advice. I had though about them before implementing my solution. and I think my running time except the part dealing with maps is O(lg n) per line of input and it is perfectly OK, and that's why I asked in forum about how to get rid of TLE. Edited by author 22.01.2009 19:36 I've reduce the number of maps in my solution and now it gives WA on test #10. Is there any tricky test cases? I used maps, set, vectors, cin & cout and my program works 0.875. There is no need in scanf(). What's test 14? Try something like: 3 a() : real a(real) : int a(int) : real 3 auto b = a() int c = a(b) auto d = a(c) Output should be: b : real d : real Can Smb Explain The Prob. Or The Sample Output nim[0] = 0, nim[1] = 1; i = 2..n, b = {0..i} j = 0..i { left = max(0, j-1); right = max(0, i - j -2); v = nim[left] ^ nim[right]; exclude (b, v) } nim[i] = min{x, which, x in b} ...... Is This way right? I'm WA #8.Who can tell me why?Need HELP!!! 1. Even number of changes does not change the color. For eg : B -> W -> B 2. Odd number of changes equals to 1, B->W and vice versa Try this test: 0 0 0 5 5 6 6 1 1 1 2 2 1 Maybe test 5 is even more simple (I'm only sure that A, B and S lie on the same line and the answer is "Impossible"), but this test shows incorrectness of some logic. 0 0 10 4 0 100 0 1 1 -1 3 1 9 ans: 30 0 It's true. BUT what in test #15????? Input should be similar to this : for i:=1 to n do read(ch); If eoln then readln; I am using a brute force, but it gives me time limit exceed on case 4, which is n = 8. can anyone tell me how to speed up this, thanks! hehe,, found a good solution to it... problem solved! So Am I - how did you improve the performance ? How did you speed it up? 1.. try brute force to get the total number of sums of digits within n/2 2.. try DP, I think it will be similar to problem 1036 Edited by author 16.12.2011 18:52 1). Use depth-first search 2). Use local variable for color in dfs procedure dfs is enough, but it's better to store graph using compliance matrix, so keeping it in this way, your dfs will visit all nodes (1) and only when current node is already colored (2). If some of node, that we can go fro current is already colored and it has the same color, so -1 should be returned. 4 memory or 30000 memory ? I have WA 28 Also. First 27 test I have passed with N=3 using Dejkstra. But N==4 means very many possible states 27*27*27*27*4*50 and unprocessing. optimal program use 4 or less cells It's evident that using 5 cells we will have better solution for rather long strings, but jury's programm can't work properly in this situation. Their hight level is 4 when they garantee right answer. I easy found Dejkstra's solution for N=3. But for N=4 I tried DP,BFS with absolutely bad characteristics. If solution depend on unproven statements which help diminish cardinality of set of possible states then it is unfair. It's possible to work with DP over 27*27*27*4*50 states for 4 modifiable cells. Yes, this uses some interesting assumption but it is provable. P.S: got AC Edited by author 14.07.2008 02:52 Edited by author 14.07.2008 03:54 Could you tell me what's your assumption? I think DP should be 27^4 * 4 * 50, and I assume that we just need modify 3 cells... so I got wa#28~ could anybody help me? sorry for my poor English. I think you can assume that cell with position 0 <= i < 4 already have needed char. I have access violation on the test 7! Help me, please! This is my code, sorry for my bad English! #include <iostream> using namespace std; int main() { int n; cin>>n; int a=0; int c=0; char nMatrix[100][31]; char str[10]; bool nArray[100]; cin.getline(str,10); for(int i=0;i<n;i++) { cin.getline(nMatrix[i],31); } for(int i=0;i<n;i++) { nArray[i] = false; } for(int i=0;i<n;i++) { if(!nArray[i]) { for(int j=i;j<n;j++) { if(strcmp(nMatrix[i],nMatrix[j])==0) { nArray[j] = true; a++; } } } if(a!=0) a--; c+=a; a=0; } cout<<c<<endl; return 0; } char nMatrix[1000][31]; bool nArray[1000]; Thank you!!! I'm real lol)))) On my computer it is working correctly. var a : array [1..100, 1..100] of integer; result : array [1..20000] of integer; i, j, ah, b, n, count : integer; begin readln (n); for i := 1 to n do begin for j := 1 to n do read (a[i, j]); readln; end; for i := 1 to (n*2-1) do begin if (i < n) then begin ah := i; b := 1; end else begin ah := n; b := i - n + 1; end; while (ah>=1) do begin inc (count); result [count] := a [ah, b]; dec (ah); inc (b); end; end; for i := 1 to count do if (result [i] <> 0) then write (result [i]); writeln; end. I think u should write " " after each number |
|