Hot_Potato's blog

By Hot_Potato, history, 8 months ago, In English

Given a list of strings lst and a list of integers p, reorder lst so that every lst[i] gets placed to p[i]. Example 1 Input

lst = ["a", "b", "c", "d"] p = [3, 0, 1, 2] Output

["b", "c", "d", "a"] Explanation

a goes to index 3 b goes to index 0 c goes to index 1 d goes to index 2

I am trying to solve this by decomposing permutation p into a product of transposition(swaps) and then use those swaps to reorder lst.. can anyone give me the code for decomposing a permutation into a product of transpositions? Note it has to be done in O(1) space..otherwise it is trivial

Read more »

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

By Hot_Potato, history, 11 months ago, In English

Find a pair of integers (A,B) such that A**5 − B**5 =X for a given integer X..this is from atcoder beginner level contest...How to solve this ? I checked the editorial but it's not clear.

https://atcoder.jp/contests/abc166/tasks/abc166_d .

Read more »

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

By Hot_Potato, history, 12 months ago, In English

https://codeforces.com/problemset/problem/1339/B Hello, i am getting runtime error on this...Can anyone help me out..when i test samples on my own laptop, it is working out fine!!

T = int(input())

for s in range(1,T+1):

N = int(input())

l = [int(input()) for i in range(N)]

l.sort()

p = []

x = len(l)

while (len(l)>2):

    p = [l[0],l[-1]] + p

    l = l[1:-1]

p = l + p


print(*p,sep=" ")

Read more »

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