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

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

Автор godmodegod, история, 6 недель назад, По-английски

Here's my attempt at solving the problem 1829G

I've started from the bottom nth row and worked my way up from there. The set considered has all the values that have already been taken before. This solution fails for the sample test case when n = 1434( gives 80385350, should give 63145186)

Code

Where am I messing up here?

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

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

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

You are given the following:

  • A tree with N nodes
  • An array A denoting the value of each node
  • A non-negative integer K

You can do the following operation on the tree at most once:

  1. Pick a node r and make it the root of the tree.
  2. In the new tree, pick a node x, and for each node v in the subtree of x, update A[v] = A[v] XOR K.

Task

Determine the maximum sum of values of all the nodes in the tree that can be obtained.

Notes

  • 1-Based indexing.
  • XOR denotes the Bitwise XOR operator.
  • A subtree of a node contains all the nodes that are descendants of that node and the node itself.

Example

Assumptions

  • N = 3
  • edges = [(1, 2), (1, 3)]
  • A = [1, 1, 3]
  • K = 3

Answer

  • The maximum sum is 7.

N can be up to 10^5.

How do we do indp and outdp calculations here?

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

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

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

A chain is a sequence of positive integers A1, A2, A3, ..., An such that Ai+1 divides Ai. (In other words, A1 is a divisor of A2, A2 is a divisor of A3, and so on.)

The length of a chain is the number of elements in the sequence.

Given N elements, you need to find a chain of maximum length using a subset of the given elements.

1<=N<=1e6 1<=a[i]<=1e6

Now, you can sort the array and track gcd (LIS like approach), but how do you come up with a solution which adheres to the time limit?

N = 5 array = 4 2 5 80 4

ans = 4, i.e. [2,4,4,80]

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

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