alessandrosolbiati's blog

By alessandrosolbiati, history, 5 months ago, In English,

==================

http://codeforces.com/contest/988/problem/B

n = int(input())
a = sorted((input() for _ in range(n)), key=lambda x: len(x))
v = all(a[i] in a[i+1] for i in range(n-1))
print('YES\n'+"\n".join(a) if v else 'NO')

==================

http://codeforces.com/contest/994/problem/A

R = lambda: (int, input().split())
n, a, b = R(), R(), R()
print(' '.join(map(str, (x for x in a if x in b))))

==================

http://codeforces.com/contest/994/problem/B

R = lambda: map(int, input().split())
n, k = R(), 
v, t = [], [0]*n
for p, c, i in sorted(zip(R(), R(), range(n))):
    t[i] = sum(v)+c
    v += [c]
    v = sorted(v)[::-1]
    if len(v) > k:
        v.pop()
print(' '.join(map(str, t)))

==================

http://codeforces.com/contest/754/problem/A

n, a = int(input()), list(map(int, input().split()))
x = next((i for i, ai in enumerate(a) if ai), None) # find index of first non-zero elements in a
if x is None:
    print('NO')
elif sum(a):
    print('YES', 1, '1 {}'.format(n), sep='\n')
else:
    print('YES', 2, '1 {}'.format(x + 1), '{} {}'.format(x + 2, n), sep='\n')

==================

http://codeforces.com/contest/996/problem/B


import math n, a, m, res = int(input()), [*(map(int,input().split()))], 10e9,-1 k = [ math.ceil((ai-i)/n) for i,ai in enumerate(a) ] print(k.index(min(k))+1)

==================

*find more here https://github.com/SolbiatiAlessandro/pyComPro

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

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by alessandrosolbiati (previous revision, new revision, compare).

»
5 months ago, # |
  Vote: I like it +9 Vote: I do not like it
v = sorted(v)[::-1]

My eyes are bleeding.

  • »
    »
    5 months ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    Why? Seems like legit way to say 'sort in decreasing order'

    • »
      »
      »
      5 months ago, # ^ |
        Vote: I like it +34 Vote: I do not like it

      Well, the purpose of this blog is to show some elegant python and not introduce obvious overkills :)
      It can be easily reduced to

      v.sort(reverse = True)
      
»
5 months ago, # |
Rev. 3   Vote: I like it +13 Vote: I do not like it

Here's another submission by kevinsogo on this problem -> http://codeforces.com/contest/989/problem/A that I found really cool.

a = raw_input()
print 'Yes' if set('ABC') in map(set, zip(a, a[1:], a[2:])) else 'No'
»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

correct way to print array and iterable in python 3:

l = [1, 2, 3, 4, 5]
print(*l, sep=' ')
print(*range(5))
»
5 months ago, # |
  Vote: I like it +8 Vote: I do not like it

lambda: (int, input().split())

lambda: map(int, input().split())?

key=lambda x: len(x)

key=len

v = sorted(v)[::-1]

v.sort(reverse=True)

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

I feel you should have used CF API rather than scraping HTML

One of the potential way is to iterate through every contest and get the list of submissions through contest.status .It returns a list of Submission objects . Only downside is that you'll need to somehow create a whitelist of the user IDs .

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by alessandrosolbiati (previous revision, new revision, compare).

»
5 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Very nice python code short and strong but some overkills might confuse newbies :)

»
3 months ago, # |
Rev. 4   Vote: I like it +1 Vote: I do not like it

Your second code isn't OK.I checked it.It gave me WA in test case 1.

Correct code :

R = lambda : list(map(int,input().split()))
n,a,b = R(),R(),R()
print(*(x for x in a if x in b))