hello
i was trying to solve this problem on a2oj https://a2oj.com/p?ID=292 and it keeps giving me wrong answer and i don't know where is the mistake in my equations so any help is appreciated
my sol : https://ideone.com/DWHlAD
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
hello
i was trying to solve this problem on a2oj https://a2oj.com/p?ID=292 and it keeps giving me wrong answer and i don't know where is the mistake in my equations so any help is appreciated
my sol : https://ideone.com/DWHlAD
Name |
---|
Can you please briefly explain what everything in your code does? People aren't interested in debugging unreadable and unannotated code.
Also make a class for modular arithmetic for god's sake, with this thing:
%mod))%mod )%mod;
you're bound to make an error sooner or later.Anyway this is how you can get out of those situations: make a program to generate thousands of small test cases. Make another "naive" solution (or in this case you can copy someone's accepted solution) and compare the outputs on the small test cases. This way you're bound to find a small test case where your program gives the wrong output. Then you can find out where your logic is wrong.
thanks for your hints , the code is really a mess , the problem is that i can't get an accepted solution for the problem as the website doesn't allow it and i searched google and it have no solution online
i have cleaned my code a bit here https://ideone.com/Hxju1m
first in my code i get the xck of k from 1 to x and store them in an array to use it later same for yck
and i get the factorial of all numbers and the modulus inverse of all of them
then i get
only inclusive functions : we get them when the A subset is smaller than the B subset like : when X = 2 and Y = 3 so only inclusive functions we can get when A = 1 , B= 2,3 and when A = 2 , B=3 , so i loop on the lengths where len(A) < len(B) and i get the npk(len(B),len(A)) and multiply it by all combinations of B from Y with this length of B and after i get all the number of functions with all lengths of B to this certain length of A , i multiply it with the combinations of A from X with this length of A
only surjective functions : we get them when the B subset is smaller than the A subset like in the previous example the only surjective functions are A=2,3 B= 1 and A=3 B=2 so i don the opposite of the only injective functions but here the number of functions i get differently i get the factorial of the length of B to distribute all elements of B on A and then the rest of places of A i put on them the rest of elements of B with all the combinations to do so
bijective functions : we get them when length of A is equal to B so i loop on all equal lengths and compute the number of functions by getting all the permutations of distribute B elements on A without repetitions
the total number of functions : we loop all over the lengths of A and B and get all the diffrent permutations of this two lengths
if even u could solve it and give me the accepted solution i would be grateful
You can always write a completely naive, brute-force solution that iterates over all possible functions or something like that. It doesn't need to be fast enough or anything. But make something that is "obviously correct" and compare its outputs to the outputs of your program, with thousands of small inputs.
I can look at your code later but try this. That's the single most effective way to find bugs or mistakes in thinking.