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 | 3557 |

2 | Um_nik | 3395 |

3 | Radewoosh | 3344 |

4 | Benq | 3316 |

5 | LHiC | 3302 |

6 | Petr | 3293 |

7 | wxhtxdy | 3286 |

8 | mnbvmar | 3274 |

9 | yutaka1999 | 3190 |

10 | ainta | 3180 |

# | User | Contrib. |
---|---|---|

1 | Errichto | 192 |

2 | Radewoosh | 176 |

3 | PikMike | 164 |

4 | Vovuh | 163 |

5 | rng_58 | 161 |

6 | majk | 157 |

6 | 300iq | 157 |

8 | antontrygubO_o | 156 |

9 | Um_nik | 149 |

10 | kostka | 148 |

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

↑

↓

Codeforces (c) Copyright 2010-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Sep/23/2019 00:24:38 (e1).

Desktop version, switch to mobile version.

Supported by

User lists

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.