Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя Naaz

Автор Naaz, история, 13 месяцев назад, По-английски

I recently encountered a DP question at least that's what i could make up for it. It goes :

You are given two numbers N, P, find the number of tuple of size N such that the product of adjacent numbers are at most P. Two tuples are considered different if the order of elements are different in them. Since the number can be large output it modulo 1e9+7.

Constraints : 2 <= N <=100 1 <= P <=1e9

Please help me with this problem and suggest some problems like this, if you can. Thanks.

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор Naaz, история, 15 месяцев назад, По-английски

i recently submitted a code to the task 1436C - Binary Search but one submission where i used the modular inverse to calculate nPr went straight passed without any hassle.so then i decided to create a struct which would create all the factorial and inverse and would contain the correlated function for calculating the nPr and nCr under a certain modulo.

Here is the code for it.


struct BINO { ll N; vector<ll> fact, inv; BINO(ll n) { N = n; fact = vector<ll>(N + 10); inv = vector<ll>(N + 10); fact[0] = fact[1] = 1; FOR(i, 2, N) fact[i] = (fact[i - 1] * i) % MOD; FOR(i, 0, N) inv[i] = bin_pow(fact[i], MOD - 2); } ll bin_pow(ll b , ll e) { ll res = 1; while ( e) { if ( e & 1) res = (res * b) % MOD; b = (b * b) % MOD; e /= 2; } return res % MOD; } ll fac(ll k ) { return fact[k] % MOD;} ll nPR(ll n , ll r) { return ( fact[n] * inv[n - r]) % MOD; } ll nCR(ll n , ll r) { return (((fact[n] * inv[n - r]) % MOD) * inv[r]) % MOD; } };

fair enough i thought to check the correctness of the code by submitting to the same question once again. But it failed at a certain test case

2 2 0 the answer to this task is 0 which my local compiler is also giving. But somehow the codeforces compiler is giving wrong answer. i have checked for integers overflows but cant find any , but when used custom test on codeforces with CLANG 20 diagnostics. it showed some overflow.

Please help me to find the integer overflow. Or is it some default behaviour of gcc which I don't know about. Any help would be totally beneficial.

Here is my accepted submission. 211400470

Полный текст и комментарии »

  • Проголосовать: нравится
  • -2
  • Проголосовать: не нравится

Автор Naaz, история, 15 месяцев назад, По-английски

can you please tell me how do you print new line. after a a for loop.

	for (int i = 0; i < n; i++) {
		cout << i << " \n"[i == n - 1];
	}

As you can see in the above code it automatically prints newline when i == n-1. and I don't prefer to use ternery operator for this case. (It takes time to write. haha) But can this be done with printf(); Just asking. If it can be done please tell me how?

Happy Coding.

P.S : I use FastOlympicCoding extension in sublime text so it kind of takes into consideration the extra white at the end and does not give correct answer verdict.But the code snippet above mentioned it does not.

Полный текст и комментарии »

  • Проголосовать: нравится
  • -9
  • Проголосовать: не нравится

Автор Naaz, история, 16 месяцев назад, По-английски

Hello, I most fail to solve a specific type of question in all platforms. Like 1840B - Бинарная кофейня. or this codechef question

It's not with the tags that i am concerned with rather the type of questions where we are required to output values in straight forward (O(1)) type computation. Like deriving a formulate and few base cases. So please if you have some suggestions for these type of questions please help me out.

Happy Coding.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится