File tree 3 files changed +112
-0
lines changed
3 files changed +112
-0
lines changed Original file line number Diff line number Diff line change
1
+ n , k = map (int , input ().split ())
2
+ s = list (map (int , list (input ())))
3
+ comp = []
4
+
5
+ c = 1
6
+ p = s [0 ]
7
+ for i in range (1 , n ):
8
+ if s [i ] == p :
9
+ c += 1
10
+
11
+ else :
12
+ comp .append ([s [i - 1 ], c ])
13
+ c = 1
14
+ p = s [i ]
15
+
16
+ comp .append ([s [n - 1 ], c ])
17
+
18
+ l = len (comp )
19
+ count = 0
20
+ d = 0
21
+ sum_ = 0
22
+ ans = []
23
+ while d < l :
24
+ if comp [d ][0 ]== 1 and count == k :
25
+ sum_ += comp [d ][1 ]
26
+ break
27
+
28
+ elif comp [d ][0 ]== 0 :
29
+ count += 1
30
+ sum_ += comp [d ][1 ]
31
+ d += 1
32
+
33
+ ans .append (sum_ )
34
+ for j in range (d + 1 , l , 2 ):
35
+ if j < l :#明示
36
+ sum_ += comp [j ][1 ]
37
+
38
+ if j + 1 < l :
39
+ sum_ += comp [j + 1 ][1 ]
40
+
41
+ if j - k * 2 - 1 >= 0 :
42
+ sum_ -= comp [j - k * 2 - 1 ][1 ]
43
+
44
+ if j - k * 2 >= 0 :
45
+ sum_ -= comp [j - k * 2 ][1 ]
46
+
47
+ ans .append (sum_ )
48
+
49
+ if not ans :
50
+ print (n )
51
+ else :
52
+ print (max (ans ))
Original file line number Diff line number Diff line change
1
+ #AC with PyPy3, TLE with Python3
2
+
3
+ #import numpy as np
4
+ h , w = map (int , input ().split ())
5
+ field = [input () for _ in range (h )]
6
+ acc_field = [[0 ]* w for _ in range (h )]
7
+ ans = 0
8
+ for i in range (h ):
9
+ to_right = [0 ]* w
10
+ to_left = [0 ]* w
11
+ to_right [0 ] = 1 if field [i ][0 ] == '.' else 0
12
+ to_left [w - 1 ] = 1 if field [i ][w - 1 ] == '.' else 0
13
+
14
+ for j in range (1 , w ):
15
+ to_right [j ] = to_right [j - 1 ] + 1 if field [i ][j ] == '.' else 0
16
+ to_left [w - j - 1 ] = to_left [w - j ] + 1 if field [i ][w - j - 1 ] == '.' else 0
17
+
18
+ for j in range (w ):
19
+ acc_field [i ][j ] = max (0 , to_right [j ]+ to_left [j ]- 1 )
20
+
21
+ for j in range (w ):
22
+ to_lower = [0 ]* h
23
+ to_upper = [0 ]* h
24
+ to_lower [0 ] = 1 if field [0 ][j ] == '.' else 0
25
+ to_upper [h - 1 ] = 1 if field [h - 1 ][j ] == '.' else 0
26
+
27
+ for i in range (1 , h ):
28
+ to_lower [i ] = to_lower [i - 1 ] + 1 if field [i ][j ] == '.' else 0
29
+ to_upper [h - i - 1 ] = to_upper [h - i ] + 1 if field [h - i - 1 ][j ] == '.' else 0
30
+
31
+ for i in range (h ):
32
+ acc_field [i ][j ] += max (0 , to_lower [i ]+ to_upper [i ]- 1 )
33
+ ans = max (ans , acc_field [i ][j ]- 1 )
34
+
35
+ print (ans )
36
+ #print(max(0, np.max(acc_field)-1))
37
+
Original file line number Diff line number Diff line change
1
+ n = int (input ())
2
+ dic_a = dict ()
3
+ dic_b = dict ()
4
+
5
+ for i in range (1 , n + 1 ):
6
+ s = str (i )
7
+ if dic_a .get ((s [0 ], s [- 1 ])):
8
+ dic_a [(s [0 ], s [- 1 ])] += 1
9
+ else :
10
+ dic_a [(s [0 ], s [- 1 ])] = 1
11
+
12
+ if dic_b .get ((s [- 1 ], s [0 ])):
13
+ dic_b [(s [- 1 ], s [0 ])] += 1
14
+ else :
15
+ dic_b [(s [- 1 ], s [0 ])] = 1
16
+
17
+ ans = 0
18
+ for key in dic_a .keys ():
19
+ if dic_b .get (key ):
20
+ inter = dic_b [key ] * dic_a [key ]
21
+ ans += inter
22
+
23
+ print (ans )
You can’t perform that action at this time.
0 commit comments