Common Board| Show all threads Hide all threads Show all messages Hide all messages | | Time Limit Exceeded WA11 | garra | 1100. Final Standings | 27 Mar 2013 18:02 | 1 | #include<stdio.h> #include<stdlib.h> int main() { long unsigned int a[15000][2],i,j,n,temp,b,c; scanf("%ld",&n); for(i=0;i<n;i++) { scanf("%lu%lu",&b,&c); if(b<=10000000&&c<=100) { a[i][0]=b; a[i][1]=c; } else { return 0; } } for(i=0;i<n;i++) { for(j=0;j<n-i;j++) { if(a[j][1]<a[j+1][1]) { temp=a[j][0]; a[j][0]=a[j+1][0]; a[j+1][0]=temp; temp=a[j][1]; a[j][1]=a[j+1][1]; a[j+1][1]=temp; } } } for(i=0;i<n;i++) { for(j=0;j<2;j++) { printf("%d ",a[i][j]); } printf("\n"); } return 0; } Edited by author 27.03.2013 18:08 | | WA 2 What is test 2? | xurshid_n | 1604. Country of Fools | 27 Mar 2013 12:58 | 2 | You can try with 2 2 3 The output should look like this 2 1 2 1 2 | | Why WA#2 what's wrong? | kami_botanik | 1563. Bayan | 27 Mar 2013 02:21 | 1 | her's my cod! Please help! using System; namespace ConsoleApplication1 { class Program1563 { static void Main() { int n = int.Parse(Console.ReadLine()); string str; string[] strl = new string[n]; int s = -1; for (int i = 0; i < n; i++) { str = Console.ReadLine(); strl[i] = str; Console.WriteLine("i="+i); for (int j = 0; j < i; j++) { if (str == strl[j]) s++; } }
Console.WriteLine(s); Console.ReadLine(); } } }
| | Hint on WA#3 | Pong Eksombatchai | 1111. Squares | 26 Mar 2013 23:59 | 2 | When you compare in the sort, try using epsilon = 1e-8. When I used 1e-13, I keep getting WA#3. I didn't understand that squares could be rotated. My solution works with both EPS = 1e-7 and 1e-14. Edited by author 26.03.2013 23:59 | | What is the best algorithm? | asdsdf | 1588. Jamaica | 26 Mar 2013 21:13 | 7 | I use O(n^3), but i meet time problem. Can you help me? Of course, the best complexity is O(N^2 log N), but O(N^3) can get AC. Can anybody in short explain how to create O(N^2 logN) algorithm, please? I've already accepted O(n^3) solution and there's no promlem with it(definitely not the best implementation of this algorithm got ac in 0.2 sec), but how to create O(N*NlogN) algo? Use angle sort, after use binary search. I've Accepted O(N*NlogN) :) N^2 * log(N^2) algo: 1) Sort n^2 lines by distance. 2) Iterate from largest to smallest. 3) We have to add line to the answer, if we not have bigger line in set, covering this. We can easily check it with set. O(N^3) easily gets AC in 0.078s. | | WA - но почему?! | deamont | 1567. SMS-spam | 26 Mar 2013 18:24 | 1 | #include <iostream> int ClickCount(char c); using namespace std; int main() { char Buf[1001]; cin.getline(Buf,1001); int Result=0; int i=0; while (Buf[i]!='\0') { Result+=ClickCount(Buf[i]); i++; } cout << Result; //system("pause");
return 0; } int ClickCount(char c) { char AlphaBet[]="abcdefghijklmnopqrstuvwxyz*.,!# *"; for (int i=0;i<=sizeof AlphaBet;i++) { if (c==AlphaBet[i]) return i%3+1; } return 0; } | | Too easy | beefmoney | 1563. Bayan | 26 Mar 2013 16:17 | 3 | It took me 2 minutes to finish it. This problem is similar to the 1496. I changed several lines of code and ACed it from first attempt. The frase "There are no brands, that differ only in register" suggests that the "Mexx" and "MEXX" is the same brand, but in fact this condition just does not make sense. I agree, this problem wasn't really a problem | | explain plz | giorgi | 1009. K-based Numbers | 26 Mar 2013 14:56 | 3 | if N=3 k=10 is 011 valid(i mean may the valid number start with 0?) 011 is actually 11 so no. a small hint: first, lets consider A ∈ { 1, 2, 3, ..., k-1} the numbers that are invalid should look like this: A00, where A can take any value from those above. no matter what values do N and K take, your numbers must always start with A. if not, then u have a number with N-1 elements. hope this helps. this reply was quite late :-) | | Solution - Wrogn Answer!!! Why? Java | badion | 1785. Lost in Localization | 26 Mar 2013 03:36 | 2 | import java.util.*; public class LavinInteractive {
public static void main(String[] args) { int n; Scanner rc = new Scanner(System.in); System.out.print("Введите число: "); n = rc.nextInt();
if (( n >= 1 ) && (n <= 4)) { System.out.print("few"); } else if (( n >=5 ) && (n <= 9)) { System.out.print("several"); } else if (( n >= 10 ) && (n <= 19)) { System.out.print("pack"); } else if (( n >= 20 ) && (n <= 49)) { System.out.print("lots"); } else if (( n >= 50 ) && (n <= 99)) { System.out.print("horde"); } else if (( n >= 100 ) && (n <= 249)) { System.out.print("throng"); } else if (( n >= 250 ) && (n <= 499)) { System.out.print("swarm"); } else if (( n >= 500 ) && (n <= 999)) { System.out.print("zounds"); } else if ( n >= 1000 ) { System.out.print("legion"); }
} } System.out.print("Введите число: "); =) quess reason | | Clarification | ibra (TNU) | 1469. No Smoking! | 25 Mar 2013 23:44 | 3 | могут ли сигареты накладываться друг на друга? например: 0 0 0 2 0 1 0 3 спасибо конечно за совет, но я знаю что эта задача есть и в Кормене и на емаксе. Я просто уточнял могут ли отрезки накладываться | | Time limit exceeded | Kanatbek | 1880. Psych Up's Eigenvalues | 25 Mar 2013 22:19 | 3 | po4emu u menia Time Limit Exceeded? ( Edited by author 12.06.2012 08:19 #include <iostream> using namespace std; int main() { int a[4000],a2[4000],a3[4000],i,j,l,n,n2,n3,k=0; cin>>n; for(i=1;i<=n;i++) cin>>a[i]; cin>>n2; for(j=1;j<=n2;j++) cin>>a2[j]; cin>>n3; for(l=1;l<=n3;l++) cin>>a3[l]; for(i=1;i<=n;i++) { for(j=1;j<=n2;j++) { for(l=1;l<=n3;l++) { if(a[i]==a2[j] && a[i]==a3[l]) k++; } } } cout<<k; return 0; } Edited by author 12.06.2012 08:25 Your algorithm has complexity O(N^3) while N = 4000. It is very long. Try to use binary search, then you will find solution with complexity O(N * logN * logN). This problem can be solved by O(N) time... If you have a good hash function, of course And O(N * log N) instead of yours O(N * log N * log N) using map. Edited by author 25.03.2013 22:24 | | where is wrong?Help me,please! | csyzcyj | 1209. 1, 10, 100, 1000... | 25 Mar 2013 20:13 | 3 | My program(LANG c)is in the following: #include<stdio.h> #include<stdlib.h> #include<cmath> int k[60000],value,i,n; int main() { scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d",&k[i]); for(i=1;i<=n;i++) { if(k[i]==0) printf("0 "); else { value=(int)sqrt((k[i]-1)*2); if((value*(value+1))==2*(k[i]-1)) if(i==n) printf("1\n"); else printf("1 "); else if(i==n) printf("0\n"); else printf("0 "); } } return 0; } BUT it can't compile,said that " d9b0f699-b537-45eb-b286-ce7765096c87d9b0f699-b537-45eb-b286-ce7765096c87(16) : error C2668: 'sqrt' : ambiguous call to overloaded functionS:\checker\compile\vc10\include\math.h(589): could be 'long double sqrt(long double)' S:\checker\compile\vc10\include\math.h(541): or 'float sqrt(float)' S:\checker\compile\vc10\include\math.h(127): or 'double sqrt(double)' while trying to match the argument list '(int)' " BUT in my computer(Windows 7),I can compile and run it,and the answer is right. So I don't know where is wrong?And I don't know how to modify it.Help me,please! Edited by author 22.02.2013 15:09 length array int k[65535] becouse (1 ≤ N ≤ 65535) My program(LANG c)is in the following: ................... int k[60000],value,i,n; ................... value=(int)sqrt((k[i]-1)*2); // sqrt(double((k[i]-1)*2)) ................... Edited by author 22.02.2013 15:09 your wrong is use (int) with sqrt. template for SQRT is sqrt(double). you must to give for sqrt double variable, and if you need int variable, you must to appropriate value in int variable. Signs after a comma will be removed. I am sorry for my bad English. Edited by author 25.03.2013 20:14 | | Error in the third test. | -XraY- | 1538. Towers of Guard | 25 Mar 2013 17:58 | 1 | There is some trash in the end of file. | | 1005 - stone pile | gogreen | 1005. Stone Pile | 25 Mar 2013 14:58 | 1 | hello, I wrote the code for this problem in python. I sure my logic is right, but do not know why i get a wrong answer. I have pasted my code below. If someone could help me find where the bug is .. it would be of great use #timus 1005 import sys,math class Timus1005: def __init__(self): pass
def minimumDiffrence(self,weights): weights.sort() if (len(weights) == 1): return weights[0]
if (len(weights) == 2): return (weights[1] - weights[0])
weights.reverse()
pile1 = 0 pile2 = 0
for stone in weights: added = False if (pile1 < pile2) and added == False: pile1 = pile1 + stone added = True
if (pile1 > pile2) and added == False: pile2 = pile2 + stone added = True
if (pile1 == pile2) and added == False: pile1 = pile1 + stone added = True
return int(math.fabs(pile1 - pile2))
if __name__ == "__main__": w = [] for line in sys.stdin: for word in line.split(' '): w.append(int(word))
p = Timus1005() print p.minimumDiffrence(w[1:])
| | To Admins | r1d1 | 1208. Legendary Teams Contest | 25 Mar 2013 14:43 | 1 | My greedy algorithm have 'accepted', but gives wrong answer for this test: 8 a b c d e f g i k b l m l m i i k c d e c e f k | | How to solve this problem? (+) | Al.Cash | 1594. Aztec Treasure | 25 Mar 2013 03:38 | 13 | The number of ways to tile an MxN rectangle with 1x2 dominos is 2^(M*N/2) times the product of { cos^2(m*pi/(M+1)) + cos^2(n*pi/(N+1)) } ^ (1/4) over all m,n in the range 0<m<M+1, 0<n<N+1. I have found this formula in internet and I would like to know is there a way to use it for solving this problem? There is a solution of this problem which doesn't use this formula. But it uses something related to the problem name :) Don't you mean Aztec Diamond? And how is it connected then? =) Your guess is correct. The connection, however, is quite unobvious. The answer can be calculated as number of perfect matching in corresponding planar graph using Kasteleyn theorem. But it uses determinant of matrix (nm/2)x(mn/2) (symmetric and with zeroes) and complex numbers, so now i don't know, can or cannot it to be applied to this problem. Hm, maybe it gives the formula posted by Al.Cash :-)))) Edited by author 21.06.2009 20:59 Yes, it gives exactly this formula =) But you can't use it due to precision reasons. We need integral-numbers formula... Very interesting from theoretical and practical point of view to use Java.BigDecimal with 1000-10000 digits and catch right answer. Connection with Aztec Diamond! Something interest, but only for (2n)x(2n) squares: Consider the 2n-by-2n matrix View the MathML source with mi,j=1 for i,j satisfying |2i−2n−1|+|2j−2n−1|less-than-or-equals, slant2n and mi,j=0 for all other i,j, consisting of a central diamond of 1's surrounded by 0's. When ngreater-or-equal, slanted4, the λ-determinant of the matrix M (as introduced by Robbins and Rumsey [Adv. Math. 62 (1986) 169–184]) is not well defined. However, if we replace the 0's by t's, we get a matrix whose λ-determinant is well defined and is a polynomial in λ and t. The limit of this polynomial as t→0 is a polynomial in λ whose value at λ=1 is the number of domino-tilings of a 2n-by-2n square. Nice problem! Finally got accepted after trying for 2 hours. best, Josh Bao Edited by author 25.06.2009 12:34 2zbao: I think this gave us no useful information! Edited by author 25.06.2009 15:27 Your submissions looks like some binary search or other cheatings... Why you get different wrongs many times for tests 29,33,34,36,38,40,42? P.S. Sorry, if I am wrong. Edited by author 25.06.2009 19:39 Wolfram Mathematica 8 allows you to use this formula with trigonometry. He is a genius! It's a wonderful package!!! :) | | Is it a right idea? | PrankMaN | 1180. Stone Game | 25 Mar 2013 03:29 | 1 | My first solution printed 2, if first player wins and the number of rocks is even and printed 1 if it's odd. And this solution got WA9. After printing "some variable" mod 3 the solution got AC. But why did my first idea fail? | | Different language, different verdict | Adilbek_ | 1011. Conductors | 24 Mar 2013 22:50 | 1 | I realize my idea on Java and Pascal. On java i got TLe on 22 test, but on Pascal i got AC with time 0.069. Not good when problem depends on the language. | | Not my decision (admins) | ONU_sneltyn | 1149. Sinus Dances | 24 Mar 2013 19:46 | 1 | It's not me posted if you can remove it? Thanks! Edited by author 24.03.2013 19:47 | | Why TLE??? | Accepted | 1635. Mnemonics and Palindromes | 24 Mar 2013 18:46 | 1 | I test my code at my computer,I got a test which is filled by period string "abcde" and its length is 4000,and my program run only 0.25s. My computer is: Memory:3GB System:Windows XP CPU:1.66GHZ But I got tle at #32...Why??? Here is my code. var i,j,xx,ox,t,l:longint; s:ansistring; f,x:array [1..4010] of longint; o:array [0..4010] of boolean; function pdhw(l,r:longint):boolean; var i:longint; begin if l=r then exit(true); for i:=l to (l+r)>>1+1 do if s[i]<>s[r+l-i] then exit(false); exit(true); end; begin readln(s); l:=length(s); for i:=1 to l do begin f[i]:=maxlongint; if pdhw(1,i) then f[i]:=0 else for j:=1 to i-1 do if (f[i]>f[j]+1)and(pdhw(j+1,i)) then begin f[i]:=f[j]+1; x[i]:=j; end; end; writeln(f[l]+1); xx:=l; repeat ox:=xx; xx:=x[xx]; if ox=l then o[xx+1]:=true else o[xx+1]:=true; until xx=0; o[1]:=false; for i:=1 to length(s) do if o[i] then write(' ',s[i]) else write(s[i]); end. |
|
|