Common Board Edited by author 07.04.2013 13:13 GIVE ME SOME TESTS 41,40 100,40 40,100 60,60 73,68 Can anyone please give me a hint to solve this problem. Please dont give the recurrence. Thank you. Let project all segments to some line (x,y --> z=ax+by) and try all pairs of segments, which have an intersection of projections. To do it just sort events "open segment", "close segment" and brute force pairs. You will get TL. Yet. Now let try 4 lines: (a,b) = (1,0) (0,1) (1,1) (1,-1). At first, let estimate number of pairs to process for each line in O(nlogn) time. Now that we may choose line, which produces minimal mumber of pairs. AC in 0.937 seconds. id = 4870936. I am getting TLE on test 24. How will you choose from which town to start? Because of this I had to start from every town to find the answer. For each town it took me O(n),so for all the towns it becomes O(n^2), causing TLE. Actually that's the main issue for this problem. If you want a hint - that's it: try to develop some dynamic programming scheme for solution. Edited by author 05.04.2013 16:20 Edited by author 05.04.2013 16:20 Finally AC! Slight implementation change got me AC!. Edited by author 05.04.2013 16:19 Edited by author 05.04.2013 16:19 I don't understand what's the hint in this problem! I read it and I think this code must be enough to solve that problem in c#: using System; namespace ConsoleApplication1 { class Program1243 { static void Main() { ulong n = Convert.ToUInt64(Console.ReadLine()); Console.WriteLine(n%7);
} } } But I get WA#5. And I don't understand! Can someone help me? . . .
10^50 does not fit into UInt64. BigInteger integer does. However you could try to divide string by 7, or use some more sophiscated math (O(N), no divisions at all). OZone UTF-8 5 Apr 2013 02:54 Please add UTF-8 encoding HTTP tag to http://acm.timus.ru/getsubmit.aspx so we could see our comments written in native languages. At least for C#. Or just to files that were submitted with UTF-8 preamble. I'm using only notepad. 29 lines. Got AC after first sending. :-) This problem is so easy, so you should not think that all this is because you are a true-coder. we so proud of you. better tell what you did for solve that problem except just telling why you awesome, coz it does not make other people happy. WA#4 was because I didn't count last partially filled line. WA#10 was because I've got overflow in the following test: 1 3 4 a aaa aaa aaa Should be 4, but I had 2. [code deleted] Edited by moderator 01.12.2019 21:24 сделайте массив побольше) char s[101] Edited by author 04.06.2012 14:33 [code deleted] There is a error with c[100], but c[101] can work... I can't understand. Edited by moderator 01.12.2019 21:25 Additional 1 is for null-terminating character. My algo works with 255 Kb memory and 1ms. what can I improve in code to get ~120 KB, as in best results? [code deleted] Edited by moderator 04.12.2019 20:44 1) You don't need d. 2) If you'd like to improve speed even further, I suggest you to flag out elements in P that you have reached. In this case you'll get O(N) instead of O(N^2). What's the answer for this test? 3 1 1 1 25000000 10001 1 1 -90000 -999890001 I'm using BigInteger arithmethic and BinSearch, but still WA2... 1) D<0: answer 1 2) sum(0, k-1):f(x1+i) -> as result, we need to compare a^2*(2*k-1)^2 and 9*D what's wrong? Edited by author 03.04.2013 18:40 Output of my (AC) program: 1 2 190523 I used standard C++ double type to solve it - it seems there're no difficult tests that fail it (or such tests are just impossible) BTW, for the case (2) my solution considers two different cases I found bug in logic, but still... 1) D<0: 1 2) a) sum(0, k-1):f(x0+0.5+i) -> as result, we need to compare F(x0+0.5) and a*(k-1)/2.0 + a*(k-1)*(2*k-1)/6.0 -> then multiply by 2 b) sum(0, k-1):f(x0+i) -> as result, we need to compare F(x0)/2.0 and a*(k-1)*(2*k-1)/6.0 -> then multiply by 2 and substract 1 Some more tests: 7 1 1 0 1 6 -9 1 0 -1 1 1000000000 -1000000000 1000000000 -1000000000 -1000000000 1234 987654321 -987654321 100000000 987654321 -987654321 Please give me some tests. I use DFS,but WA4. Edited by author 19.05.2011 17:52 Check this one :-) >> 12 >> 8 8 8 1 1 8 8 8 1 1 8 8 << 68 Edited by author 10.08.2012 14:29 shouldnt the answer be 67 instead of 68? -> 1 1 8 8 8 1 1 8 8 -> 1 1 1 1 8 8 -> 1 1 1 total: 44 + 20 + 3 = 67 ? EDIT: Its my mistake sorry, you are right, after shooting the walls still reamin adjacent even if the adjacent wall is shot. Edited by author 04.04.2013 13:10 Edited by author 04.04.2013 13:10 Edited by author 04.04.2013 13:32 Edited by author 04.04.2013 13:32 Здравствуйте! Никак не могу понять где у меня проблема. На домашнем компьютере всё нормально работает, но здесь постоянно выдаёт WA. Спасибо #include <stdio.h> #include <math.h> int main(void) { long num; long double arr[100000]; int position = 0; int asnwer; while ( ( asnwer = scanf("%lu", &num)) != EOF ) { if ( asnwer == 1 ) { arr[position] = num; position++; } } position--; while (position >= 0) { printf("%.4f\n", sqrt( arr[position] )); position--; } //getchar(); return 0; } 1. Your code is compiler-dependent: long == int on some compilers, so never use it. Use int or long long explicitly 2. Why do you think 100000 array is enough? Thank you for your answer. 1) Ok, i made it. 2) Actually if i try to raise after 100.000 i get "Runtime error (stack overflow)". So maybe there is some another trick i didn't get. Best regards Use global array to avoid stack overflow subj! I could solve this task only when I've seen someone mention about stable results (used TreeSet with comparator, 0.4", 15.5 Mb memory) You should notice that bubble sort mentioned in problem statement is stable I wrote kd-tree based solution but still TL#16, and I cannot find bad cases for my realization (on my local machine it finishes within 1 sec on any test). Any ideas of what kind of tests may these be? Edited by author 26.03.2013 04:00 //please help me to solve this problem //my Bug is between the stars. #include <iostream> using namespace std; int main() { int n,s=1; cin >> n; int a[n]; for( int i=0;i<n;i++ ) { cin >> a[i]; } for( int i=0;i<n-1;i++ ) { if( a[i]!=a[i+1] ) s++; } int b[s][2]; for( int i=0;i<s;i++ ) { b[i][1]=-1; b[i][0]=0; } b[0][0]=1; b[0][1]=a[0]; //************************************************************************** for( int i=0; i<n-1;i++ ) { if( a[i]!=a[i+1] ) { int j; for( j=1;j<s;j++ ) { if( b[j][1]=-1 ) break; } b[j][1]=a[i+1]; b[j][0]++; } else if( a[i]==a[i+1] ) { int j; for( j=1;j<s;j++ ) { if( b[j][1]=-1 ) break; } b[j-1][0]++; } } //************************************************************************** for( int i=0;i<s;i++ ) { cout << b[i][0] << " " << b[i][1]<< " "; } return 0; } |
|