aeonary's blog

By aeonary, history, 11 months ago, In English

Given a grid of size $$$M \times N, (1 \le M, N \le 2000)$$$ where each cell contains an integer $$$A_ij, (|A_ij| \le 250)$$$. We have to find the maximum path from (1, 1) to any cell in the last row. Allowed moves are right, left, and bottom.

I've used DP to solve this problem, where $$$DP[i][j]$$$ equals the maximum path sum from (1, 1) to (i, j). Then I got 2 cases: the first one is that we can get to (i, j) from (i — 1, j), and from (i, j) we can move left or right such that the left sum and the right sum is positive, so initially, $$$DP[i][j] = DP[i-1][j] + A[i][j] + maxPrefix[i][j - 1] + maxSuffix[i][j + 1]$$$. Cases number 2 is that we can get to (i, j) from (i, k), and (i, k) is from (i — 1, k), and then from (i, k) we can move to the left if $$$k < j$$$, then move to the right of j: $$$DP[i][j] = DP[i - 1][k] + sum[j..k] + maxPrefix[i][k - 1] + maxSuffix[i][j + 1]$$$ or we can move to the right from (i, k) if $$$j < k$$$, then move to the left of j: $$$DP[i][j] = DP[i - 1][k] + sum[j..k] + maxPrefix[i][j - 1] + maxSuffix[i][k + 1]$$$. But I got WA with this solution, please help me to solve this problem (sorry that I don't have the submission link).

Full text and comments »

  • Vote: I like it
  • -8
  • Vote: I do not like it

By aeonary, history, 16 months ago, In English
  • Vote: I like it
  • 0
  • Vote: I do not like it

By aeonary, history, 16 months ago, In English

Please help me, the number is find the longest fibonacci-like subsequence

  • t <= 15
  • N <= 2500
  • -10^6 <= a[i] <= 10^6

Example

Input:

1

7

-20 87 20 0 20 100 22

Output: 4 (-20, 20, 0, 20)

Full text and comments »

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

By aeonary, history, 16 months ago, In English

Please help me, the statement is: count number of triplets x, y, z (x, y, z >= 0) that (x^d + y^d + z^d) mod N = m mod N

  • 1 ≤ T ≤ 10 (number of test cases)
  • 1 ≤ U ≤ 109
  • 0 ≤ d ≤ 109
  • 1 ≤ N ≤ 40
  • 0 ≤ m < N

example:

input:

  • 2
  • 2 2 3 5
  • 1 2013 3 31

output:

  • 4 explain: (0,2,2),(2,2,0),(2,0,2),(1,1,1)
  • 1 explain: (1,1,1)

Full text and comments »

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

By aeonary, history, 17 months ago, In English

Please help me. The statement is: Give an array A with n integers(n <= 10^5). Your task is to find the longest increasing subsequence that gcd of 2 consecutive elements is > 1.

Example:

input

5

2 3 4 6 9

output

4

Full text and comments »

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

By aeonary, history, 18 months ago, In English

Please help me, the statement is:

Give N (N <= 10^5) pair (x, y). Count number of triads i, j, k (i != j != k) that (X_i + X_j + X_k) % 3 = 0 and (Y_i +

Y_j + Y_k) % 3 = 0

Example:

Input:

6

1 2

2 5

4 0

8 1

5 3

10 7

Output:

2

Explain: (1,3,6) and (2,4,5)

Full text and comments »

  • Vote: I like it
  • -3
  • Vote: I do not like it

By aeonary, history, 18 months ago, In English

Please help me, the statement is:

On the plane of the Cartesian coordinate system, give N points numbered from 1 to N Each point i (1 ≤ i ≤ N) has integer

coordinates (xi, yi). Candidates start from point 1, in turn move in order to points 2, 3, ..., N and they can skip exactly K

points (except 1 and N). The distance between two points (xi, yi) and (xj, yj) is | xi — xj | + | yi — yj |. Find the shortest

way to move from point 1 to point N and skip K points.

Example:

Input: N, K and N points

5 2

0 0

7 3

1 1

8 -5

2 2

Output:

4

Explain: Skip point 2 and point 4

Full text and comments »

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

By aeonary, history, 18 months ago, In English

Please help me, the statement is: Give an matrix size n * m (n * m <= 10^6), from a square, we can move to 4 square that common side. Find the longest path that increasing

example:

3 5

1 2 2 8 9

2 3 1 7 10

1 4 5 6 1

10

Full text and comments »

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

By aeonary, history, 19 months ago, In English

Problem: give an array A of N (1 <= N <= 2 * 10^6) integer. Find the number of good triplets (i, j, k), where i, j, k are all distinct indices such that 1 <= i < j < k <= N. A good triplet (i, j, k) is a triplet such that A[i] = x, A[j] = y, A[k] = z(x, y, z are given numbers).

Example 1:

Input: 5

1 2 2 1 2

1 2 1

Output:

2

Explanation: two triplets are (1,2,4) and (1,3,4)

Example 2:

Input:

5

1 2 2 1 2

2 1 1

Output:

0

Explanation: there are no good triplets

Full text and comments »

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

By aeonary, history, 19 months ago, In English

Statement: a sequence of numbers with 2k elements called "Double" if with k elements from left and k from right, we can create k

pairs that two elements in each pair are equal. Give an array A with n elements, n is even, L numbers at the left and R number at

the right. You can perform these following operations on A any number of times (possibly zero):

  • replace A_i with x (x <= n)

  • move 1 element from L to R

  • move 1 element from R to L

Find the minimum number of operations to make A be a double sequence.

Example:

Input: n, L, R and A

6 3 3

1 2 3 2 2 2

Output: minimum number of operations

2

Please help me!!!

Full text and comments »

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