backupkid's blog

By backupkid, history, 20 minutes ago, In English

Hi reader , i came across with this problem and can only solve 2 subs . Im stuck and have no idea how to solve the harder subtasks.

u re given a weighted DAG ($$$n \le 3\cdot 10^5$$$, $$$m \le 5\cdot 10^5$$$, edge weights $$$|c| \le 1000$$$) with a source $$$s$$$ and sink $$$t$$$. Whenever you reach $$$t$$$, you can jump back to $$$s$$$ with cost $$$0$$$ and start another run.

We consider a sequence of $$$D$$$ paths $$$P_1,P_2,\ldots,P_D$$$ from $$$s$$$ to $$$t$$$, where $$$D \le 10^{18}$$$. For a fixed vertex $$$v$$$, we choose exactly one of the $$$D$$$ paths that passes through $$$v$$$ to activate it.

The contribution of this sequence and activation choice is:

$$$ \left(\sum_{i=1}^{D} W(P_i)\right)^K \pmod{998244353} $$$

where $$$W(P_i)$$$ is the total weight of path $$$P_i$$$, and $$$K \le 2000$$$.

We need to calculate the answer for every vertex $$$v$$$.

Input

The first line contains four positive integers $$$n, m, K, D$$$ ($$$2 \le n \le 3 \cdot 10^5$$$, $$$1 \le m \le 5 \cdot 10^5$$$, $$$0 \le K \le 2000$$$, $$$1 \le D \le 10^18$$$).

The second line contains two positive integers $$$s, t$$$ ($$$1 \le s, t \le n$$$, $$$s \ne t$$$).

Each of the next $$$m$$$ lines contains three integers $$$u, v, c$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$, $$$|c| \le 10^3$$$), representing a directed edge from vertex $$$u$$$ to vertex $$$v$$$ with weight $$$c$$$.

Output

Print $$$n$$$ integers on a single line, where the $$$v$$$-th integer is the total energy obtained by placing a resonance station at vertex $$$v$$$, modulo $$$998244353$$$.

Subtasks:

  1. $$$K=0,\ D=1$$$.

  2. $$$D=1,\ K\le 50$$$.

  3. $$$D\le 10^{18},\ K\le 20,\ n\le 1000$$$.

  4. $$$D\le 10^{18},\ K\le 50,\ n\le 3\cdot 10^5$$$.

  5. $$$D\le 10^{18},\ K\le 2000,\ n\le 3\cdot 10^5$$$.

input
5 6 0 1
1 5
1 4 1
4 5 1
1 2 1
2 3 1
3 5 1
1 3 1
output
3 1 2 1 3
input
4 4 1 1
1 4
1 2 1
2 4 2
1 3 3
3 4 4
output
10 3 7 10

any hints would be appreciate , thank u !

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it

By backupkid, history, 5 months ago, In English

Hello reader!

I came across this problem and I'm not sure how to approach it. Any hints would be appreciated!

Problem:

The Fibonacci sequence is defined as F(0) = 1, F(1) = 1, F(n) = F(n-1) + F(n-2). So: 1, 1, 2, 3, 5, 8, 13, 21, 34, ...

Given N, count the number of ways to write N as a product of Fibonacci numbers, where each factor is > 1. Order does not matter (2×4 and 4×2 are the same representation).

Example: Input: 4 2 7 40 64 Output: 1 0 2 3

Constraints: - T ≤ 50 test cases - N can be up to 10^18

I have no idea where to start. How do you approach this kind of problem?

Thank you!

update : the problem was solved

solotion 1: Top-Down DP with Memoization author MEDAAA

Idea
Code

solution 2: Greedy + Math author:phsads

Idea
Code

Complexity Comparison

Approach Time per Query Space Notes
DP Memoization $$$O(\text{Fib}^2 \log N)$$$ $$$O(\text{Fib} \log N)$$$ More intuitive, general DP
Greedy + Math $$$O(\log N)$$$ $$$O(\text{Fib})$$$ Faster, uses number theory

Credits

can u give me contribution :) Thanks to MEDAAA, phsads, Ahmed-Nawaz, InfiniteLoops1730, VladiG, Metall1cA, HelperT27, and others for all the discussions and ideas in the comments. Really appreciate the different approaches and insights — from DP attempts to number theory explanations.

Full text and comments »

  • Vote: I like it
  • +10
  • Vote: I do not like it