File tree Expand file tree Collapse file tree 5 files changed +150
-0
lines changed
AlgoFlux Online Qualifier Expand file tree Collapse file tree 5 files changed +150
-0
lines changed Original file line number Diff line number Diff line change
1
+ # cook your code here
2
+ a = []
3
+ n = 10 ** 6 + 10 ** 5
4
+ prime = [True for i in range (n + 1 )]
5
+ p = 2
6
+ while (p * p <= n ):
7
+ # If prime[p] is not changed, then it is a prime
8
+ if (prime [p ] == True ):
9
+
10
+ # Update all multiples of p
11
+ for i in range (p * 2 , n + 1 , p ):
12
+ prime [i ] = False
13
+ p += 1
14
+ # Print all prime numbers
15
+ for p in range (2 , n ):
16
+ if prime [p ]:
17
+ a .append (p + 1 )
18
+ # print(a)
19
+
20
+ for kohli in range (int (raw_input ())):
21
+ n = int (raw_input ())
22
+ # print(a)
23
+ print (a [n ]* - 1 )
Original file line number Diff line number Diff line change
1
+ for _ in range (input ()):
2
+ arr = list (raw_input ())
3
+ string = ''
4
+ for i in arr :
5
+ if ord ('A' )<= ord (i )<= ord ('D' ):
6
+ string += 'A'
7
+ elif ord ('E' )<= ord (i )<= ord ('H' ):
8
+ string += 'H'
9
+ elif ord ('I' )<= ord (i )<= ord ('K' ):
10
+ string += 'I'
11
+ elif ord ('L' )<= ord (i )<= ord ('N' ):
12
+ string += "M"
13
+ elif ord ("O" )<= ord (i )<= ord ("Q" ):
14
+ string += "O"
15
+ elif ord ("R" )<= ord (i )<= ord ("T" ):
16
+ string += "T"
17
+ elif i == "U" or i == "V" or i == "W" or i == "X" or i == "Y" :
18
+ string += i
19
+ elif i == "Z" :
20
+ string += "A"
21
+ print string
Original file line number Diff line number Diff line change
1
+ for kohli in range (input ()):
2
+ a = raw_input ()
3
+ b = raw_input ()
4
+ n = len (a )
5
+ m = len (b )
6
+ t = m // n
7
+ # print "aage baddd "
8
+ # print a,b,n,m
9
+ # print "aage baddd ",t
10
+ for i in range (t ):
11
+ if (b .find (a )!= - 1 ):
12
+ b = b .replace (a ,'' )
13
+ # print b
14
+ # print b
15
+ if (b == '' ):
16
+ print "YES"
17
+ else :
18
+ print "NO"
19
+
20
+ '''
21
+
22
+ 4
23
+ ab
24
+ abab
25
+ ab
26
+ aabb
27
+ ab
28
+ aba
29
+ abc
30
+ aabcbcabc
31
+
32
+ '''
Original file line number Diff line number Diff line change
1
+ '''
2
+
3
+ 1
4
+ 5 5
5
+ 0 0 0 -1 5
6
+ 0 0 0 -1 0
7
+ 1 0 0 0 0
8
+ 0 0 0 0 0
9
+ 0 0 0 0 0
10
+
11
+ '''
12
+
13
+ for _ in range (int (raw_input ())):
14
+ n ,m = map (int ,raw_input ().split ())
15
+ ar = []
16
+ mx = 0
17
+ for i in range (n ):
18
+ ar .append (map (int ,raw_input ().split ()))
19
+ # print(ar)
20
+ # print(max(ar[-1]))
21
+ mx = max (max (ar [- 1 ]),mx )
22
+ # print(mx)
23
+
24
+ vis = []
25
+ for i in range (n ):
26
+ vis .append ([0 ]* m )
27
+ # print(vis)
28
+
29
+ v = []
30
+ for i in range (mx + 1 ):
31
+ v .append ([])
32
+ # print(v)
33
+
34
+ for i in range (n ):
35
+ for j in range (m ):
36
+ if ar [i ][j ] > 0 :
37
+ v [ar [i ][j ]].append ((i ,j ))
38
+ # print v
39
+
40
+ for i in range (mx ,0 ,- 1 ):
41
+ for cx ,cy in v [i ]:
42
+ # print cx,cy
43
+ if vis [cx ][cy ] == 2 :
44
+ continue
45
+ if cx + 1 < n and ar [cx + 1 ][cy ]!= - 1 and vis [cx + 1 ][cy ]== 0 :
46
+ vis [cx + 1 ][cy ] = 1
47
+ v [i - 1 ].append ((cx + 1 ,cy ))
48
+ if cx - 1 > - 1 and ar [cx - 1 ][cy ]!= - 1 and vis [cx - 1 ][cy ]== 0 :
49
+ vis [cx - 1 ][cy ] = 1
50
+ v [i - 1 ].append ((cx - 1 ,cy ))
51
+ if cy + 1 < m and ar [cx ][cy + 1 ]!= - 1 and vis [cx ][cy + 1 ]== 0 :
52
+ vis [cx ][cy + 1 ] = 1
53
+ v [i - 1 ].append ((cx ,cy + 1 ))
54
+ if cy - 1 > - 1 and ar [cx ][cy - 1 ]!= - 1 and vis [cx ][cy - 1 ]== 0 :
55
+ vis [cx ][cy - 1 ] = 1
56
+ v [i - 1 ].append ((cx ,cy - 1 ))
57
+ vis [cx ][cy ] = 2
58
+ # print vis
59
+ # for __ in vis:
60
+ # print(__)
61
+ # print "fuck me mother-fucker"
62
+ # print v
63
+ # print v
64
+
65
+ for i in range (n ):
66
+ st = ''
67
+ for j in range (m ):
68
+ if ar [i ][j ] == - 1 :
69
+ st += 'B'
70
+ elif vis [i ][j ]> 0 :
71
+ st += 'Y'
72
+ else :
73
+ st += 'N'
74
+ print st
You can’t perform that action at this time.
0 commit comments