File tree Expand file tree Collapse file tree 2 files changed +58
-0
lines changed
Expand file tree Collapse file tree 2 files changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+ import sys
2+
3+ input = sys .stdin .readline
4+
5+ n , s = map (int , input ().split ())
6+ arr = list (map (int , input ().split ()))
7+
8+ i , j = 0 , 0
9+ prefix_sum = arr [0 ]
10+ res = float ('inf' )
11+
12+ while True :
13+ if j >= n :
14+ break
15+ if prefix_sum >= s :
16+ res = min (res , j - i + 1 )
17+ prefix_sum -= arr [i ]
18+ i += 1
19+ else :
20+ j += 1
21+ if j < n :
22+ prefix_sum += arr [j ]
23+
24+ if res != float ('inf' ):
25+ print (res )
26+ else :
27+ print (0 )
Original file line number Diff line number Diff line change 1+ import sys
2+
3+ input = sys .stdin .readline
4+
5+ n , m , k = map (int , input ().split ())
6+ board = []
7+ for _ in range (n ):
8+ board .append (list (map (str , input ().rstrip ())))
9+
10+ cnt = []
11+ for a in range (n - k + 1 ):
12+ for b in range (m - k + 1 ):
13+ white = 0
14+ black = 0
15+ for i in range (a , a + k ):
16+ for j in range (b , b + k ):
17+ # 처음 색과 같아야 하는 부분
18+ if (i + j ) % 2 == 0 :
19+ if board [i ][j ] != 'W' :
20+ white += 1
21+ else :
22+ black += 1
23+ # 처음 색과 달라야 하는 부분
24+ else :
25+ if board [i ][j ] != 'W' :
26+ black += 1
27+ else :
28+ white += 1
29+ cnt .append (white )
30+ cnt .append (black )
31+ print (min (cnt ))
You can’t perform that action at this time.
0 commit comments