| Show all threads Hide all threads Show all messages Hide all messages |
| why my program gets WA at 2 | subtlebear | 1036. Lucky Tickets | 14 Dec 2011 03:54 | 2 |
Please help me, i don't understand what is wrong with the code below import java.math.BigInteger; import java.io.*; import java.util.*; public class LuckyTickets { public static void main(String[] args) {
int N,S; BigInteger F[][] = new BigInteger[51][];
for(int i = 0; i <= 50; i++) F[i]= new BigInteger[1001];
Scanner scanner= new Scanner(System.in); try { N= scanner.nextInt(); S= scanner.nextInt();
for(int j= 0; j <= N; j++) for(int i= 0; i <= S; i++) F[j][i]= new BigInteger("0");
for(int j= 1; j <= N; j++) F[j][0] = BigInteger.ONE;
for(int i= 1; i < 10; i++) F[1][i] = BigInteger.ONE;
for(int i= 2; i <= N; i++) for(int k= 1; k <= S; k++) { for(int j= 0; j <= 9 && j <= k; j++) F[i][k]= F[i][k].add(F[i-1][k-j]); } // there are F[N][S/2] * F[N][S/2] different tickets System.out.println(F[N][S/2].multiply(F[N][S/2]));
// for(int j= 0; j <= N; j++){ // for(int i= 0; i <= S; i++) // System.out.print(F[j][i]+ " "); // System.out.println(""); // }
} catch(InputMismatchException e) { System.out.println("Mismatch exception " + e); }
} } you don't need 2-dimension F[][], just only using one-dimension BigInteger array (in your case, F[]) is enough. for(int j= 0; j <= 9 && j <= k; j++) change this to for(int j= 1; j <= 9 && j <= k; j++) check answer '0' at the begining for two cases: S is odd or S > 18 * n second dimension of F is [s + 1] instead of 1001 which kills memory.. I got accepted using Java biginteger as well, and I create the array of below: BigInteger []f = new BigInteger[s + 1]; That is it! |
| Hint for me and you) | Valdemar | 1226. esreveR redrO | 14 Dec 2011 01:49 | 1 |
Use (c>='A'&&c<='z')||(c>='a'&&c<='z') instead c>='A'&&c<='z' very stupid mistake :) I got AC Edited by author 17.12.2011 23:32 Edited by author 17.12.2011 23:32 |
| I've got WA #7. Help me, please! | felfer | 1723. Sandro's Book | 14 Dec 2011 01:36 | 1 |
const N=50; type TChastot=array [1..N] of byte; var inStr,outStr:string; chast:TChastot; i,j:integer; maxChast,iPos:integer; begin readln(inStr); for i:=1 to length(inStr) do begin chast[i]:=0; for j:=i to length(inStr) do if inStr[i]=inStr[j] then chast[i]:=chast[i]+1; end; maxChast:=Low(integer); iPos:=0; for i:=1 to length(inStr) do if maxChast<chast[i] then begin maxChast:=chast[i]; iPos:=i; end; i:=iPos; outStr:=''; while (i<=length(inStr)) and (chast[i]=chast[iPos]) do begin outStr:=outStr+inStr[i]; i:=i+1; end; if length(outStr)<length(inStr) then begin i:=pos(outStr,copy(inStr,length(outStr)+1,length(inStr)-length(outStr))); while i=0 do begin delete(outStr,length(outStr),1); i:=pos(outStr,copy(inStr,length(outStr)+1,length(inStr)-length(outStr))); end; end; writeln(outStr); end. Edited by author 14.12.2011 02:20 |
| I have AC without writing spaces between faculties! | Alex.pas | 1446. Sorting Hat | 14 Dec 2011 00:07 | 2 |
Is it mistake in example or bug?(I write on pascal) Edited by author 13.12.2011 23:41 Your output is the same as in the sample test. :) |
| Sample example. What we must find? | IgorKoval(from Pskov) | 1091. Tmutarakan Exams | 13 Dec 2011 21:28 | 4 |
How get answer 11 for K==3 and S==10 I understand it so: a b gcd(a,b) 2 4 2 2 6 2 2 8 2 2 10 2 3 6 3 3 9 3 4 2 2 4 6 2 4 8 4 4 10 2 5 10 5 6 2 2 6 3 3 6 4 2 6 8 2 6 9 3 6 10 2 8 2 2 8 4 4 8 6 2 8 10 2 9 3 3 9 6 3 10 2 2 10 4 2 10 5 5 10 6 2 10 8 2 So, cnt = 28 //count of pair a, b And my answer is 28. Why am wrong? And how use 'K'? =)
Edited by author 11.12.2011 19:36 "You should find the number of sets of K different numbers" sets of K different numbers Please, give some example of "sets of K different numbers"( there are 11 sets(from Sample example) ) for K==3 and S==10. Thank you. Edited by author 13.12.2011 21:07 Edited by author 13.12.2011 21:07 a b c fgcd(c,fgcd(a,b)) 2 4 6 2 2 4 8 2 2 4 10 2 2 6 8 2 2 6 10 2 2 8 10 2 3 6 9 3 4 6 8 2 4 6 10 2 4 8 10 2 6 8 10 2 cnt = 11 fgcd - function which return greatest common divisor Edited by Trolol 13.12.2011 21:30 Edited by author 13.12.2011 21:50 |
| ask for circle !!!!! | mwh | 1465. Pawn Game | 13 Dec 2011 18:21 | 1 |
who can tell me what's the circle is (I have tested 1000,10000...all wrong) ask for help!!!! can you help me!!! |
| Oh my GOD, C# is very good at string | DR. Zhihua Lai | 1446. Sorting Hat | 13 Dec 2011 17:57 | 1 |
usually i don't code in C# but I just found that C# is very good at this kind of problems... string manipulation is great in C#... you have many handy things such as List, Dictionary etc.. |
| How to be fast? | Artem Khizha [DNU] | 1389. Roadworks | 13 Dec 2011 15:35 | 2 |
Greetings! I have just solved this problem with DP on a tree via DFS, but it appeared to be much too slow (0.25s), though I expected a better result. There's a tree in this problem, so totally solution must be O(N). May any precial tricks be there or I just did something wrong? You need only 2 DFS. This solution get AC in 0.08s. |
| little hint. | xurshid_n | 1365. Testing Calculator | 13 Dec 2011 02:25 | 1 |
1) /(3;4)(2;0);2 Output: 1710 :) (not 34/20/2) 2) *3 ===> *3;1 /3 ===> /3;1 +3 ===> +3;0 3) () ==> (1) ==> 1 4) all brackets are balanced, and right. good luck! |
| Has anyone solve this by dynamic programming? | phizaz | 1005. Stone Pile | 12 Dec 2011 22:50 | 3 |
please tell me how do you? I found one algo but it uses memory equal to W<sub>i</sub> limitation. if maximum of W<sub>i</sub> is 100000 it uses 100000 too. Maybe it use 2 times more. Edited by author 05.04.2011 22:59 Hey, did you solve it with DP ? Please let me know how did you solve it ? Thanks |
| WA 21 | ONU_Latysh | 1601. AntiCAPS | 12 Dec 2011 22:26 | 2 |
WA 21 ONU_Latysh 12 Dec 2011 21:32 Any sugestions!? My programme passed 20 tests, so I'm surprised and don't know what to do I want to tell you guys that you need to mind this: -HI - HI the answer is: -Hi - Hi So you need to leave the capital letter in the begining of the line after '-' (ASCII is 45) |
| why test 10? | Pop Ioachim | 1545. Hieroglyphs | 12 Dec 2011 14:51 | 1 |
|
| To ALL: Unfair for Pascal programmers to compete with C++/C | DR. Zhihua Lai | | 12 Dec 2011 02:26 | 3 |
I spent two days on tweaking my code for Problem 1532 First I wrote the solution in Pascal, which solves at 0.687 sec. And I rewrite the same algo in C++/C, it gives 0.32 sec http://acm.timus.ru/status.aspx?author=46914&status=accepted So I guess the Free Pascal does not turn on {$Optimization 2}, Please, Admins, could you kindly check? and if I use "goto" in FreePascal, I will get a "Compiler (Fail)" How do I enable "goto"? I tried "{$GOTO ON}" but it does not work... anyway.. finally, my ranking for Problem 1532 has reached the second... I am happy... http://acm.timus.ru/rating.aspx?space=1&num=1532 Edited by author 11.12.2011 20:58Why do you think the same algo in C/C++ and Pascal should produce similar result in terms of time? Even if all optimizations would be enabled that doesn't mean these compilers optimizers are equally smart. If you are concerned about such imbalance just install exactly the same compilers as online judge uses, compile your programs with exactly the same options and compare assembler listings of both programs. And only if you prove the sensible difference between {$Optimization 2} and current pascal switches you may say "Unfair for Pascal programmers to compete with C++/C". I met opposite situation in 1001: the same algo gives 0.046 in pascal and 0.14 in C++. What really makes me mad is that this C++ solution required only 0.062 in 2007 :-O > if I use "goto" in FreePascal, I will get a "Compiler (Fail)" How do I enable "goto"? > I tried "{$GOTO ON}" but it does not work... You may email admins and ask them add this info into FAQ. Thanks... I will look into this... |
| Это норм? | RuslanRussel | | 11 Dec 2011 22:27 | 1 |
|
| WA #8 | Vinod Shunmugavel | 1079. Maximum | 11 Dec 2011 18:51 | 1 |
WA #8 Vinod Shunmugavel 11 Dec 2011 18:51 Can somebody help me.. Whats the 8th test case?? |
| Help me WA 9 | spark-roman | 1586. Threeprime Numbers | 11 Dec 2011 16:50 | 2 |
You probably didnt MOD correctly. I got wa in case 9 for this |
| Accepted | Habib [ Tashkent U of IT ] | 1044. Lucky Tickets. Easy! | 11 Dec 2011 16:06 | 5 |
Accepted Habib [ Tashkent U of IT ] 13 Oct 2011 19:56 #include <stdio.h>
int main() { int N; scanf("%d", &N); switch(N) { case 2: printf("10\n"); return 0; case 4: printf("670\n"); return 0; case 6: printf("55252\n"); return 0; case 8: printf("4816030\n"); return 0; default: return 0; } return 0; } Delete your code Habib!!!! its too easy, the problem is how generate all combinations possibles, can you tell me!!!!!!... |
| Read this lessons | DixonD (Lviv NU) | 1465. Pawn Game | 11 Dec 2011 13:04 | 5 |
Thank you very much! Finally I got AC. I've calculating the nim-sequence for this game about 3 hours)))) Thank you! Very useful articles. thank you sincerely!!!!!!!!!!!!!!!!! wonderful artical!!!!!!!!!!!!!! great ideas!!!!!!!!!!!!!!!!!!!!!!1 Edited by author 13.12.2011 17:50 |
| Why this problem is classified as Data Structure? | ahyangyi(newer id) | 1628. White Streaks | 11 Dec 2011 10:44 | 3 |
I feel this is somewhat misleading as Data Structure isn't necessary for this problem. Agree. Solves with sort only. Sorting is good, yes. But it can be solved with data stuctures too. I used map<int,set<int> > and it gave slow AC (0.75 sec). |
| Why WA? | Figznaetlto | 1820. Ural Steaks | 11 Dec 2011 05:24 | 1 |
Why WA? Figznaetlto 11 Dec 2011 05:24 Edited by author 11.12.2011 07:01 Edited by author 11.12.2011 07:02 |