description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
s = input() ab = [] ba = [] for i in range(len(s) - 1): if s[i : i + 2] == "AB": ab.append(i) elif s[i : i + 2] == "BA": ba.append(i) if len(ab) == 0 or len(ba) == 0: print("NO") else: works = False for i in ab: if works: break for j in ba: if works: break if i != j - 1 and i != j + 1: print("YES") works = True if not works: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF VAR FOR VAR VAR IF VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
s = input() s1 = s if "BA" in s: s = s.replace("BA", "//", 1) else: s = s.replace("AB", "//") if "AB" in s: t = True else: t = False s = s1 if "AB" in s: s = s.replace("AB", "//", 1) else: s = s.replace("BA", "//") if "BA" in s: t1 = True else: t1 = False if t or t1: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING IF STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING IF STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
s = input() AB = [x for x in range(len(s) - 1) if s[x] + s[x + 1] == "AB"] BA = [x for x in range(len(s) - 1) if s[x] + s[x + 1] == "BA"] try: print("YES" if AB[0] + 1 < BA[-1] or BA[0] + 1 < AB[-1] else "NO") except IndexError: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER STRING STRING VAR EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
inputsa = input().lower() inputs = inputsa ab_ex = False ba_ex = False it = True var1 = "ab" var2 = "ba" while 1: if inputs.find(var1) > -1: temp = inputs.find(var1) inputs = inputs[:temp] + "0" + inputs[temp + 2 :] ab_ex = True if inputs.find(var2) > -1: temp = inputs.find(var2) inputs = inputs[:temp] + "0" + inputs[temp + 2 :] ba_ex = True if ab_ex == True and ba_ex == False and it == True: inputs = inputsa var1 = "ba" var2 = "ab" ab_ex = False it = False continue break if ab_ex == True and ba_ex == True: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING WHILE NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
def take_AB(_list: [[str]]) -> bool: AB = False for i in range(len(_list) - 1): if not AB and _list[i][0] == "A" and _list[i + 1][0] == "B": _list[i][0] = "X" _list[i + 1][0] = "X" AB = True if AB: return True else: return False def take_BA(_list: [[str]]) -> bool: BA = False for i in range(len(_list) - 1): if not BA and _list[i][0] == "B" and _list[i + 1][0] == "A": _list[i][0] = "X" _list[i + 1][0] = "X" BA = True if BA: return True else: return False letter_list = [] dup_letter_list = [] string = input() for i in range(len(string)): letter_list.append([]) dup_letter_list.append([]) letter_list[i].append(string[i]) dup_letter_list[i].append(string[i]) if ( take_AB(letter_list) and take_BA(letter_list) or take_BA(dup_letter_list) and take_AB(dup_letter_list) ): print("YES") else: print("NO")
FUNC_DEF LIST LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER STRING VAR BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER VAR FUNC_DEF LIST LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR NUMBER STRING VAR BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER IF VAR RETURN NUMBER RETURN NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
s = input() n = len(s) l = [] k = [] for i in range(n - 1): if s[i] == "A" and s[i + 1] == "B": l.append([i + 1, i]) if s[i] == "B" and s[i + 1] == "A": k.append([i, i + 1]) if len(l) == 0 or len(k) == 0: print("NO") else: if abs(len(l) - len(k)) > 0 and (len(l) > 2 or len(k) > 2): flag = 1 else: flag = 0 for i in range(len(l)): if l[i][0] != k[0][0] and l[i][1] != k[0][1]: flag = 1 break for i in range(len(k)): if k[i][0] != l[0][0] and k[i][1] != l[0][1]: flag = 1 break if flag == 1: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
s = input().strip() n = len(s) T = False if s[:2] == "AB" or s[:2] == "BA": h = 1 k = [] h = [] for i in range(n - 1): if s[i : i + 2] == "AB": k.append(i) if s[i : i + 2] == "BA": h.append(i) if len(k) > 1 and len(h) > 1: print("YES") elif len(h) == 0 or len(k) == 0: print("NO") elif len(h) == 1 or len(k) == 1: if abs(h[-1] - k[-1]) == 1: print("NO") else: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER STRING VAR NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
def next(arr, target): start = 0 end = len(arr) - 1 ans = -1 while start <= end: mid = (start + end) // 2 if arr[mid] <= target: start = mid + 1 else: ans = mid end = mid - 1 return ans def isFound(s): abIndexes = [] baIndexes = [] for i in range(len(s) - 1): if s[i] == "A" and s[i + 1] == "B": abIndexes.append(i) elif s[i] == "B" and s[i + 1] == "A": baIndexes.append(i) for index in abIndexes: if next(baIndexes, index + 1) != -1: return True for index in baIndexes: if next(abIndexes, index + 1) != -1: return True return False s = input() memo = dict() if isFound(s): print("Yes") else: print("No")
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
s = input() def findPattern(): ans = "" ba_pos = s.find("BA") ab_pos = s.find("AB") if ab_pos != -1: s_new = s[ab_pos + 2 :] if s_new.find("BA") != -1: ans = "YES" else: ans = "NO" else: ans = "NO" if ba_pos != -1 and ans == "NO": s_new = s[ba_pos + 2 :] if s_new.find("AB") != -1: ans = "YES" else: ans = "NO" return ans print(findPattern())
ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR STRING IF VAR NUMBER VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR STRING NUMBER ASSIGN VAR STRING ASSIGN VAR STRING RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
s = input() AB_left = min([(i if s[i : i + 2] == "AB" else 100000000) for i in range(len(s))]) AB_right = max([(i if s[i : i + 2] == "AB" else -100000000) for i in range(len(s))]) BA_left = min([(i if s[i : i + 2] == "BA" else 100000000) for i in range(len(s))]) BA_right = max([(i if s[i : i + 2] == "BA" else -100000000) for i in range(len(s))]) print("YES" if AB_left + 1 < BA_right or BA_left + 1 < AB_right else "NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR STRING STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
import sys r = input() s = r[:] f = 0 a = "AB" b = "BA" if s.find(a) != -1: j = s.find(a) t = s[j + 2 :] if t.find(b) != -1: print("YES") sys.exit() if s.find(b) != -1: j = s.find(b) t = s[j + 2 :] if t.find(a) != -1: print("YES") sys.exit() print("NO")
IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
s = input() X = [] a = 0 l = len(s) while 1: p = s[a:l].find("AB") if p == -1: break X.append(p + a) a = a + p + 2 Y = [] a = 0 l = len(s) while 1: p = s[a:l].find("BA") if p == -1: break Y.append(p + a) a = a + p + 2 f = 0 for i in X: if f == 1: break for j in Y: if i - j >= 2 or j - i >= 2: print("YES") f = 1 break else: if f == 0: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
s = input() a = [] for i in range(len(s) - 1): if s[i] == "A" and s[i + 1] == "B": a.append((i, i + 1)) ans = False for i in range(len(s) - 1): if s[i] == "B" and s[i + 1] == "A": for x, y in a: if x not in [i, i + 1] and y not in [i, i + 1]: ans = True break if ans: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING FOR VAR VAR VAR IF VAR LIST VAR BIN_OP VAR NUMBER VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
data = input() def run(): for index in range(len(data) - 1): if data[index : index + 2] == "AB": if data[index + 2 :].count("BA") > 0: return "YES" if data[index : index + 2] == "BA": if data[index + 2 :].count("AB") > 0: return "YES" return "NO" print(run())
ASSIGN VAR FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING IF FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER RETURN STRING IF VAR VAR BIN_OP VAR NUMBER STRING IF FUNC_CALL VAR BIN_OP VAR NUMBER STRING NUMBER RETURN STRING RETURN STRING EXPR FUNC_CALL VAR FUNC_CALL VAR
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
s = input() w = "" if "AB" in s: w = s.replace("AB", ".", 1) else: print("NO") exit() if "BA" in w: print("YES") else: if "BA" in s: s = s.replace("BA", ".", 1) else: print("NO") exit() if "AB" in s: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF STRING VAR EXPR FUNC_CALL VAR STRING IF STRING VAR ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF STRING VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
s = input() n = len(s) b, b1 = [], [] for i in range(n - 1): if s[i] == "B" and s[i + 1] == "A": b1.append(i) if s[i] == "A" and s[i + 1] == "B": b.append(i) for i in range(len(b)): c = 0 if b[i] - 1 in b1: c += 1 if b[i] + 1 in b1: c += 1 if len(b1) > c: print("YES") exit() print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
a = input() t = "AB" r = "BA" if t in a and r in a: w = str(a) w = w.replace(r, " ", 1) a = a.replace(t, " ", 1) if t in w: print("YES") elif r in a: print("YES") else: print("NO") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
l = input() i = 0 f1 = False f2 = False f3 = False f4 = False while i < len(l) - 1: if (l[i] == "A" and l[i + 1] == "B") and not f1: f1 = True i += 2 elif (l[i] == "B" and l[i + 1] == "A") and not f2: f2 = True i += 2 else: i += 1 i = len(l) - 1 if not (f1 and f2): while i > 1: if (l[i] == "B" and l[i - 1] == "A") and not f3: f3 = True i -= 2 elif (l[i] == "A" and l[i - 1] == "B") and not f4: f4 = True i -= 2 else: i -= 1 if f1 and f2 or f3 and f4: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR WHILE VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
def main(): a, ab, ba = "*", [], [] for i, b in enumerate(input()): if a == "A" and b == "B": ab.append(i) elif a == "B" and b == "A": ba.append(i) a = b print(("NO", "YES")[bool(ab and ba) and (ba[-1] - ab[0] > 1 or ab[-1] - ba[0] > 1)]) main()
FUNC_DEF ASSIGN VAR VAR VAR STRING LIST LIST FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR IF VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR STRING STRING FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
a = input() p = a.count("AB") b = a.replace("AB", ".", 1) q = b.count("BA") if p > 0 and q > 0: y = 1 else: y = 0 r = a.count("BA") c = a.replace("BA", ".", 1) s = c.count("AB") if r > 0 and s > 0: x = 1 else: x = 0 if x == 1 or y == 1: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING NUMBER ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
def findAB(s): ab = s.find("AB") ba = s.rfind("BA") if ab == -1 or ba == -1: return False if ab + 1 < ba: return True ba = s.find("BA") ab = s.rfind("AB") if ba + 1 < ab: return True return False if findAB(input()): print("YES") else: print("NO")
FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
s = input() p = list(s) flag = False for i in range(len(s) - 3): if s[i] == "A" and s[i + 1] == "B": if "BA" in s[i + 2 :]: print("YES") flag = True if flag == True: break if s[i] == "B" and s[i + 1] == "A": if "AB" in s[i + 2 :]: print("YES") flag = True if flag == True: break if flag == False: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING IF STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING IF STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
s = input() ans = False ans_2 = False i = 0 l = len(s) while i < l: if not ans and s[i] == "A" and i + 1 < l and s[i + 1] == "B": ans = True i += 2 elif ans and s[i] == "B" and i + 1 < l and s[i + 1] == "A": ans_2 = True break else: i += 1 if ans * ans_2: print("YES") exit() ans = False ans_2 = False i = 0 while i < l: if not ans_2 and s[i] == "B" and i + 1 < l and s[i + 1] == "A": ans_2 = True i += 2 elif ans_2 and s[i] == "A" and i + 1 < l and s[i + 1] == "B": ans = True break else: i += 1 if ans * ans_2: print("YES") else: print("NO")
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR IF VAR VAR VAR STRING BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR STRING BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR STRING BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR STRING BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING
You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). -----Input----- The only line of input contains a string s of length between 1 and 10^5 consisting of uppercase Latin letters. -----Output----- Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. -----Examples----- Input ABA Output NO Input BACFAB Output YES Input AXBYBXA Output NO -----Note----- In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO". In the second sample test there are the following occurrences of the substrings: BACFAB. In the third sample test there is no substring "AB" nor substring "BA".
def are_substring(s): i = 0 ab = False ba = False while i < len(s) and s[i : i + 2] != "BA": i += 1 if i < len(s) and "AB" in s[i + 2 :]: ab = True j = 0 while j < len(s) and s[j : j + 2] != "AB": j += 1 if j < len(s) and "BA" in s[j + 2 :]: ba = True if ab or ba: return "YES" else: return "NO" s = input() if len(s) <= 3: print("NO") else: print(are_substring(s))
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER IF VAR FUNC_CALL VAR VAR STRING VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = input().split() n = int(n) m = int(m) mat = [] count = 0 for i in range(n): temp = input() mat.append(temp) for j in temp: if j == "*": count += 1 Map = {} ans = {} for i in range(n): for j in range(m): if mat[i][j] == "*": u = [i - 1, j] d = [i + 1, j] r = [i, j + 1] l = [i, j - 1] size = 0 while ( u[0] >= 0 and d[0] < n and r[1] < m and l[1] >= 0 and mat[u[0]][u[1]] == "*" and mat[d[0]][d[1]] == "*" and mat[l[0]][l[1]] == "*" and mat[r[0]][r[1]] == "*" ): if (u[0], u[1]) not in Map and (u[0], u[1]) not in ans: Map[u[0], u[1]] = True if (d[0], d[1]) not in Map and (d[0], d[1]) not in ans: Map[d[0], d[1]] = True if (l[0], l[1]) not in Map and (l[0], l[1]) not in ans: Map[l[0], l[1]] = True if (r[0], r[1]) not in Map and (r[0], r[1]) not in ans: Map[r[0], r[1]] = True u = [u[0] - 1, j] d = [d[0] + 1, j] l = [i, l[1] - 1] r = [i, r[1] + 1] size += 1 if size > 0: if (i, j) in Map: del Map[i, j] ans[i, j] = size if len(Map) + len(ans) != count: print(-1) else: print(len(ans)) for key in ans: print(key[0] + 1, key[1] + 1, ans[key])
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR LIST BIN_OP VAR NUMBER VAR ASSIGN VAR LIST BIN_OP VAR NUMBER VAR ASSIGN VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER NUMBER VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER STRING VAR VAR NUMBER VAR NUMBER STRING VAR VAR NUMBER VAR NUMBER STRING VAR VAR NUMBER VAR NUMBER STRING IF VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR LIST BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR LIST VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) maps = [list(input()) for i in range(n)] vis = [["." for j in range(m)] for i in range(n)] ans = [] for i in range(0, n): for j in range(0, m): if maps[i][j] == "*": length = 1 while ( i - length >= 0 and i + length < n and j - length >= 0 and j + length < m and maps[i - length][j] == "*" and maps[i + length][j] == "*" and maps[i][j - length] == "*" and maps[i][j + length] == "*" ): ( vis[i][j], vis[i - length][j], vis[i][j + length], vis[i + length][j], vis[i][j - length], ) = ("*", "*", "*", "*", "*") length += 1 if length == 1: continue ans.append([i + 1, j + 1, length - 1]) if vis != maps: print(-1) else: print(len(ans), end=" ") for it in ans: print(end="\n") print(it[0], it[1], it[2], end=" ")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR STRING STRING STRING STRING STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER STRING
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
from sys import exit, stdin def listInput(): return list(map(int, stdin.readline().rstrip().split())) n, m = listInput() mapp = [input().rstrip() for _ in range(n)] ans = [[[] for j in range(m)] for i in range(n)] for i in range(n): for j in range(m): if mapp[i][j] == ".": continue ma_k = 0 for k in range(1, min(n, m)): if ( i - k >= 0 and mapp[i - k][j] == "*" and i + k < n and mapp[i + k][j] == "*" and j - k >= 0 and mapp[i][j - k] == "*" and j + k < m and mapp[i][j + k] == "*" ): ma_k += 1 else: break if ma_k == 0: continue ans[i][j].append((i, j, ma_k)) for k in range(1, ma_k + 1): ans[i - k][j].append((i, j, ma_k)) ans[i][j - k].append((i, j, ma_k)) ans[i][j + k].append((i, j, ma_k)) ans[i + k][j].append((i, j, ma_k)) ans_set = set([]) for i in range(n): for j in range(m): for k in ans[i][j]: ans_set.add(k) nmap = [["." for j in range(m)] for i in range(n)] for a, b, c in ans_set: nmap[a][b] = "*" for k in range(1, c + 1): nmap[a - k][b] = "*" nmap[a][b - k] = "*" nmap[a + k][b] = "*" nmap[a][b + k] = "*" is_same = 1 for i in range(n): for j in range(m): if nmap[i][j] != mapp[i][j]: is_same = 0 break if is_same == 0: print(-1) else: print(len(ans_set)) for a, b, c in ans_set: print(a + 1, b + 1, c)
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR STRING BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR STRING BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR STRING BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
import sys input = sys.stdin.readline n, m = map(int, input().split()) MAP = [list(input().strip()) for i in range(n)] T0 = [([0] * (m + 1)) for i in range(n + 1)] T1 = [([0] * (m + 1)) for i in range(n + 1)] Y0 = [([0] * (m + 1)) for i in range(n + 1)] Y1 = [([0] * (m + 1)) for i in range(n + 1)] for i in range(n): for j in range(m): if MAP[i][j] == "*": T0[i][j] = T0[i - 1][j] + 1 Y0[i][j] = Y0[i][j - 1] + 1 for i in range(n - 1, -1, -1): for j in range(m - 1, -1, -1): if MAP[i][j] == "*": T1[i][j] = T1[i + 1][j] + 1 Y1[i][j] = Y1[i][j + 1] + 1 ANS = [([0] * m) for i in range(n)] for i in range(n): for j in range(m): score = min(T0[i][j], T1[i][j], Y0[i][j], Y1[i][j]) if score >= 2: ANS[i][j] = score T0 = [([0] * (m + 1)) for i in range(n + 1)] T1 = [([0] * (m + 1)) for i in range(n + 1)] Y0 = [([0] * (m + 1)) for i in range(n + 1)] Y1 = [([0] * (m + 1)) for i in range(n + 1)] for i in range(n): for j in range(m): T0[i][j] = max(ANS[i][j], T0[i - 1][j] - 1) Y0[i][j] = max(ANS[i][j], Y0[i][j - 1] - 1) for i in range(n - 1, -1, -1): for j in range(m - 1, -1, -1): T1[i][j] = max(ANS[i][j], T1[i + 1][j] - 1) Y1[i][j] = max(ANS[i][j], Y1[i][j + 1] - 1) SUF = [(["."] * m) for i in range(n)] for i in range(n): for j in range(m): if T0[i][j] or T1[i][j] or Y0[i][j] or Y1[i][j]: SUF[i][j] = "*" if SUF != MAP: print(-1) else: ANSLIST = [] for i in range(n): for j in range(m): if ANS[i][j] != 0: ANSLIST.append((i + 1, j + 1, ANS[i][j] - 1)) print(len(ANSLIST)) for ans in ANSLIST: print(*ans)
IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST STRING VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = [int(x) for x in input().split()] a = [] for _ in range(n): a.append(list(str(input()))) visited = [[(0) for i in range(m)] for j in range(n)] ans = [] for i in range(n): for j in range(m): if a[i][j] == "*": x = 1 while 1: if i + x < n and j + x < m and i - x > -1 and j - x > -1: if ( a[i + x][j] == "*" and a[i - x][j] == "*" and a[i][j + x] == "*" and a[i][j - x] == "*" ): visited[i][j + x] = 1 visited[i][j - x] = 1 visited[i - x][j] = 1 visited[i + x][j] = 1 visited[i][j] = 1 x += 1 else: break else: break if x > 1: ans.append([i, j, x - 1]) for i in range(n): for j in range(m): if a[i][j] == "*" and visited[i][j] == 0: print(-1) exit(0) print(len(ans)) for i in ans: for j in i[:-1]: print(j + 1, end=" ") print(i[-1], end=" ") print()
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR NUMBER STRING EXPR FUNC_CALL VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) s = [list(input()) for i in range(n)] dp = [["." for i in range(m)] for j in range(n)] ans = [] for i in range(1, n - 1): for j in range(1, m - 1): if ( s[i][j] == "*" and s[i + 1][j] == "*" and s[i - 1][j] == "*" and s[i][j - 1] == "*" and s[i][j + 1] == "*" ): x = 0 while ( i - x > -1 and x + i < n and j - x > -1 and x + j < m and s[i + x][j] == "*" and s[i - x][j] == "*" and s[i][j - x] == "*" and s[i][j + x] == "*" ): dp[i + x][j], dp[i - x][j], dp[i][j - x], dp[i][j + x] = ( "*", "*", "*", "*", ) x += 1 if x != 1: ans.append([i + 1, j + 1, x - 1]) else: dp[i][j] = "." if dp != s: print(-1) else: print(len(ans)) for i in ans: print(*i)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING VAR BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR NUMBER VAR STRING VAR VAR BIN_OP VAR NUMBER STRING VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING STRING STRING STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
io = input().split() n = int(io[0]) m = int(io[1]) arr = [] stars = [] res = [] def analitic(y, x): global n, m, arr maxValue = min(y, m - x - 1, n - y - 1, x) tMax = 0 for i in range(maxValue): if arr[y - i - 1][x] == ".": tMax = i break else: tMax = i + 1 rMax = 0 for i in range(tMax): if arr[y][x + i + 1] == ".": rMax = i break else: rMax = i + 1 bMax = 0 for i in range(rMax): if arr[y + i + 1][x] == ".": bMax = i break else: bMax = i + 1 lMax = 0 for i in range(bMax): if arr[y][x - i - 1] == ".": lMax = i break else: lMax = i + 1 return lMax def draw(y, x, size): global arr arr[y][x] = "." for i in range(size): arr[y - i - 1][x] = "." for i in range(size): arr[y][x + i + 1] = "." for i in range(size): arr[y + i + 1][x] = "." for i in range(size): arr[y][x - i - 1] = "." class Star: def __init__(self, y, x, size): self.y = y self.x = x self.size = size for i in range(n): arr.append(list(input())) for i in range(n - 2): for j in range(m - 2): if arr[i + 1][j + 1] == ".": continue starSize = analitic(i + 1, j + 1) if starSize: stars.append(Star(i + 1, j + 1, starSize)) for i in stars: res.append(str(i.y + 1) + " " + str(i.x + 1) + " " + str(i.size)) draw(i.y, i.x, i.size) for i in range(n): for j in range(m): if arr[i][j] == "*": print(-1) exit() count = len(res) print(count) for i in res: print(i)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER STRING CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) maze = [] for _ in range(n): maze.append(list(str(input()))) noa = 0 for i in range(n): for j in range(m): if maze[i][j] == "*": noa += 1 dp = [[(0) for j in range(m)] for i in range(n)] output = [] for i in range(1, n): for j in range(1, m - 1): if maze[i][j] == "*": for height in range(1, max(n, m)): if ( i - height < 0 or i + height > n - 1 or j - height < 0 or j + height > m - 1 ): if height != 1: output.append((i + 1, j + 1, height - 1)) break if ( maze[i - height][j] == "*" and maze[i + height][j] == "*" and maze[i][j - height] == "*" and maze[i][j + height] == "*" ): dp[i - height][j] = 1 dp[i + height][j] = 1 dp[i][j - height] = 1 dp[i][j + height] = 1 dp[i][j] = 1 else: if height != 1: output.append((i + 1, j + 1, height - 1)) break cp = 0 for i in range(n): for j in range(m): if dp[i][j] == 1: cp += 1 if cp == noa: print(len(output)) for i in output: print(*i) else: print(-1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
def all_true(stars, n, m): for i in range(n): for j in range(m): if not stars[i][j]: return False return True def get_biggest_star(ar, i, j): ans = 0 cur = i - 1 while cur >= 0 and ar[cur][j] == "*": ans += 1 cur -= 1 length = 0 cur = i + 1 while cur < n and ar[cur][j] == "*": length += 1 cur += 1 ans = min(ans, length) length = 0 cur = j - 1 while cur >= 0 and ar[i][cur] == "*": length += 1 cur -= 1 ans = min(ans, length) length = 0 cur = j + 1 while cur < m and ar[i][cur] == "*": length += 1 cur += 1 ans = min(ans, length) return ans n, m = map(int, input().split()) ar = [] stars = [] for i in range(n): cur = input() st = [] for i in range(m): if cur[i] == ".": st.append(True) else: st.append(False) stars.append(st) ar.append(cur) finalAns = [] ans = 0 for i in range(1, n - 1): for j in range(1, m - 1): if ar[i][j] == ".": continue length = get_biggest_star(ar, i, j) if length > 0: ans += 1 finalAns.append([i + 1, j + 1, length]) stars[i][j] = True temp = 0 while temp < length: temp += 1 stars[i - temp][j] = True temp = 0 while temp < length: temp += 1 stars[i + temp][j] = True temp = 0 while temp < length: temp += 1 stars[i][j - temp] = True temp = 0 while temp < length: temp += 1 stars[i][j + temp] = True if all_true(stars, n, m): print(ans) for i in finalAns: print(*i) else: print(-1)
FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) qw = 0 grid = [None] * n for i in range(n): grid[i] = list(input()) ANS = [] def star(x, y, i): if x < i or x >= n - i or y < i or y >= m - i: return 0 if grid[x][y] == ".": return 0 for j in range(1, i + 1): if ( grid[x + i][y] == "." or grid[x - i][y] == "." or grid[x][y + i] == "." or grid[x][y - i] == "." ): return 0 return 1 for i in range(n): for j in range(m): for k in range(1, min(n, m) // 2 + 2): if star(i, j, k) == 1: continue else: if k > 1: ANS += [(i, j, max(k - 1, 1))] break grid2 = [None] * n for i in range(n): grid2[i] = ["."] * m def draw(x, y, i): grid2[x][y] = "*" for i in range(1, i + 1): grid2[x + i][y] = "*" grid2[x - i][y] = "*" grid2[x][y + i] = "*" grid2[x][y - i] = "*" for i in ANS: draw(i[0], i[1], i[2]) for i in range(n): for j in range(m): if grid[i][j] == "*": qw = 1 break if qw == 1: break if qw == 0: print(0) elif grid != grid2 or ANS == []: print(-1) else: print(len(ANS)) for i in ANS: print(i[0] + 1, i[1] + 1, i[2])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF IF VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER IF VAR VAR VAR STRING RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR LIST VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NONE VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIST STRING VAR FUNC_DEF ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) S = [list(str(input())) for _ in range(n)] L = [([0] * m) for _ in range(n)] R = [([0] * m) for _ in range(n)] U = [([0] * m) for _ in range(n)] D = [([0] * m) for _ in range(n)] for i in range(n): cnt = 0 for j in range(m): if S[i][j] == ".": cnt = 0 else: cnt += 1 L[i][j] = cnt cnt = 0 for j in reversed(range(m)): if S[i][j] == ".": cnt = 0 else: cnt += 1 R[i][j] = cnt for j in range(m): cnt = 0 for i in range(n): if S[i][j] == ".": cnt = 0 else: cnt += 1 U[i][j] = cnt cnt = 0 for i in reversed(range(n)): if S[i][j] == ".": cnt = 0 else: cnt += 1 D[i][j] = cnt T = [(["."] * m) for _ in range(n)] ans = [] for i in range(1, n - 1): for j in range(1, m - 1): if S[i][j] == ".": continue l = L[i][j] - 1 r = R[i][j] - 1 u = U[i][j] - 1 d = D[i][j] - 1 s = min([l, r, u, d]) if s == 0: continue ans.append((i + 1, j + 1, s)) for p in range(i - s, i + s + 1): T[p][j] = "*" for q in range(j - s, j + s + 1): T[i][q] = "*" for i in range(n): for j in range(m): if S[i][j] != T[i][j]: print(-1) exit() else: print(len(ans)) for i in range(len(ans)): print(*ans[i])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) s = [input() for row in range(n)] f = [[((column == "*") & 1) for column in row] for row in s] vis = [[(0) for i in range(0, m)] for j in range(0, n)] result = [] def allvis(vis, f, n, m): sum1 = 0 sum2 = 0 for i in range(0, n): for j in range(0, m): sum1 += vis[i][j] == 1 sum2 += f[i][j] == 1 return sum1 == sum2 for row in range(0, n, 1): for column in range(0, m, 1): if f[row][column] == 1: cnt = 0 for i in range(1, max(n, m)): if row - i >= 0 and column - i >= 0 and row + i < n and column + i < m: if ( f[row - i][column] == f[row + i][column] == f[row][column + i] == f[row][column - i] == f[row][column] ): vis[row - i][column] = 1 vis[row + i][column] = 1 vis[row][column - i] = 1 vis[row][column + i] = 1 vis[row][column] = 1 cnt = i else: break else: break if cnt != 0: result.append([row + 1, column + 1, cnt]) if not allvis(vis, f, n, m): print(-1) else: print(len(result)) for i in range(0, len(result), 1): print(result[i][0], result[i][1], result[i][2])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR STRING NUMBER VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) center = {} t = [] for i in range(n): t.append([]) s = input() for j in s: t[-1].append(j) if t[0][0] == "*" or t[n - 1][m - 1] == "*" or t[0][m - 1] == "*" or t[n - 1][0] == "*": print(-1) else: for s in range(min(n, m) // 2 + 1, 0, -1): for i in range(s, n - s): for j in range(s, m - s): if t[i][j] != "." and str(i + 1) + " " + str(j + 1) not in center: p = True c = 1 while c <= s and p: if t[i + c][j] == ".": p = False if t[i][j + c] == ".": p = False if t[i - c][j] == ".": p = False if t[i][j - c] == ".": p = False c += 1 if p: t[i][j] = 1 c = 1 while c <= s: t[i + c][j] = 1 t[i][j + c] = 1 t[i - c][j] = 1 t[i][j - c] = 1 c += 1 center[str(i + 1) + " " + str(j + 1)] = s f = False for i in range(n): for j in range(m): if t[i][j] == "*": f = True break if f: print(-1) else: print(len(center)) for i in center: print(i, center[i])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER NUMBER STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER STRING VAR NUMBER BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER NUMBER STRING EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR STRING BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR IF VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) a = [[" " for i in range(m)] for j in range(n)] for i in range(n): a[i] = list(input()) check = [["." for i in range(m)] for j in range(n)] MAX_STAR_SIZE = min(n, m) // 2 ans = [] def valid_star(i, j, s): if s <= 0: return False if i - s < 0 or i + s >= n or j - s < 0 or j + s >= m: return False if ( a[i + s][j] == "." or a[i - s][j] == "." or a[i][j + s] == "." or a[i][j - s] == "." ): return False return True def place_star(x, y, sz): global check check[x][y] = "*" for i in range(1, sz + 1): check[x + i][y] = "*" check[x - i][y] = "*" check[x][y + i] = "*" check[x][y - i] = "*" def star_complete(): global check for i in range(n): for j in range(m): if a[i][j] != check[i][j]: return False return True for i in range(n): for j in range(m): if a[i][j] != "*": continue sz = 0 for s in range(1, MAX_STAR_SIZE + 1): if valid_star(i, j, s): sz = s else: break if sz != 0: place_star(i, j, sz) ans.append([i + 1, j + 1, sz]) if not star_complete(): print(-1) else: print(len(ans)) for i in ans: print(*i, sep=" ")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR RETURN NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
def CheckStar(n, m, i, j, a): s = 1 while i - s >= 0 and i + s < n and j - s >= 0 and j + s < m: if ( a[i - s][j] >= 1 and a[i + s][j] >= 1 and a[i][j - s] >= 1 and a[i][j + s] >= 1 ): a[i][j] += 1 a[i - s][j] += 1 a[i + s][j] += 1 a[i][j - s] += 1 a[i][j + s] += 1 s = s + 1 else: return s - 1 return s - 1 def StarsDrawing(n, m, a, c): i = 1 ans = 0 final = [] cc = 0 while i < n - 1: j = 1 while j < m - 1: if a[i][j] >= 1: star = CheckStar(n, m, i, j, a) if star >= 1: ans = ans + 1 final.append([i + 1, j + 1, star]) j = j + 1 i = i + 1 for i in range(n): for j in range(m): if a[i][j] > 1: cc = cc + 1 if cc < c: print(-1) return -1 else: print(len(final)) for f in final: print(f[0], "", f[1], "", f[2]) nm = list(map(int, input().rstrip().split())) graph = [] c = 0 for i in range(nm[0]): graph.append([]) t = input() tt = [] for j in t: if j == "*": tt.append(1) c = c + 1 else: tt.append(0) graph[i] = tt StarsDrawing(nm[0], nm[1], graph, c)
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) s = [input() for row in range(n)] f = [[((column == "*") & 1) for column in row] for row in s] result = [] seq_row = [[] for row in range(0, n)] seq_column = [[] for column in range(0, m)] dp = [[[(0) for _ in range(0, m)] for __ in range(0, n)] for ___ in range(0, 2)] def all_vis(): merge_row = [[] for row in range(0, n)] merge_column = [[] for column in range(0, m)] vis = [[(0) for row in range(0, m)] for column in range(0, n)] for i in range(0, n): left = -1 right = -1 seq_row[i].sort() for j in range(0, len(seq_row[i])): if left == -1: left = seq_row[i][j][0] right = seq_row[i][j][1] elif left <= seq_row[i][j][0] <= right: right = max(right, seq_row[i][j][1]) else: merge_row[i].append((left, right)) left = -1 right = -1 if left != -1 and right != -1: merge_row[i].append((left, right)) for i in range(0, m): left = -1 right = -1 seq_column[i].sort() for j in range(0, len(seq_column[i])): if left == -1: left = seq_column[i][j][0] right = seq_column[i][j][1] elif left <= seq_column[i][j][0] <= right: right = max(right, seq_column[i][j][1]) else: merge_column[i].append((left, right)) left = -1 right = -1 if left != -1 and right != -1: merge_column[i].append((left, right)) for i in range(0, n): for j in range(0, len(seq_row[i])): for k in range(seq_row[i][j][0], seq_row[i][j][1] + 1): vis[i][k] = 1 for i in range(0, m): for j in range(0, len(seq_column[i])): for k in range(seq_column[i][j][0], seq_column[i][j][1] + 1): vis[k][i] = 1 sum1 = 0 sum2 = 0 for i in range(0, n): for j in range(0, m): sum1 += vis[i][j] == 1 sum2 += f[i][j] == 1 return sum1 == sum2 def init_dp(): for i in range(0, n): dp[0][i][0] = f[i][0] for j in range(1, m): dp[0][i][j] = dp[0][i][j - 1] + f[i][j] for j in range(0, m): dp[1][0][j] = f[0][j] for i in range(1, n): dp[1][i][j] = dp[1][i - 1][j] + f[i][j] def get(row, column, mid): if not ( row - mid >= 0 and row + mid < n and column - mid >= 0 and column + mid < m ): return False l = dp[0][row][column - 1] r = dp[0][row][column + mid] - dp[0][row][column] u = dp[1][row - 1][column] d = dp[1][row + mid][column] - dp[1][row][column] if row - mid != 0: u = u - dp[1][row - mid - 1][column] if column - mid != 0: l = l - dp[0][row][column - mid - 1] return l == r == u == d == mid def b_search(left, right, row, column): mid = (left + right) // 2 while left != mid and mid != right: if not get(row, column, mid): right = mid else: left = mid mid = (left + right) // 2 if get(row, column, right): return right if get(row, column, left): return left return -1 init_dp() for row in range(0, n, 1): for column in range(0, m, 1): if f[row][column]: max_size = b_search(1, max(n, m), row, column) if max_size > 0: seq_row[row].append((column - max_size, column + max_size)) seq_column[column].append((row - max_size, row + max_size)) result.append([row + 1, column + 1, max_size]) if not all_vis(): print(-1) else: print(len(result)) for i in range(0, len(result), 1): print(result[i][0], result[i][1], result[i][2])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR STRING NUMBER VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_DEF IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR RETURN VAR IF FUNC_CALL VAR VAR VAR VAR RETURN VAR RETURN NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) arr = [input() for i in range(n)] s1 = set() s2 = set() res = list() for i in range(n): for j in range(m): if arr[i][j] == "*": s1.add((i, j)) l = 1 while True: if i - l >= 0 and i + l < n and j - l >= 0 and j + l < m: if ( arr[i - l][j] == arr[i + l][j] == arr[i][j - l] == arr[i][j + l] == "*" ): s2 |= {(i - l, j), (i + l, j), (i, j - l), (i, j + l)} l += 1 else: break else: break l -= 1 if l > 0: s2.add((i, j)) res.append([i + 1, j + 1, l]) if len(s1 - s2) > 0: print(-1) else: print(len(res)) for x in res: print(*x)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
import sys from itertools import accumulate def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [([c] * b) for i in range(a)] def list3d(a, b, c, d): return [[([d] * c) for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[([e] * d) for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print("Yes") def No(): print("No") def YES(): print("YES") def NO(): print("NO") INF = 10**18 MOD = 10**9 + 7 def build_grid(H, W, intv, _type, space=True, padding=False): if space: _input = lambda: input().split() else: _input = lambda: input() _list = lambda: list(map(_type, _input())) if padding: offset = 1 else: offset = 0 grid = list2d(H + offset * 2, W + offset * 2, intv) for i in range(offset, H + offset): row = _list() for j in range(offset, W + offset): grid[i][j] = row[j - offset] return grid H, W = MAP() grid = build_grid(H, W, "#", str, space=0, padding=1) ans = [] imosw = list2d(H + 2, W + 2, 0) imosh = list2d(H + 2, W + 2, 0) def check(i, j): sz = min(L[i][j], R[i][j], U[i][j], D[i][j]) if sz > 1: imosw[i][j - sz + 1] += 1 imosw[i][j + sz] -= 1 imosh[i - sz + 1][j] += 1 imosh[i + sz][j] -= 1 ans.append((i, j, sz - 1)) def check2(): for i in range(1, H + 1): for j in range(1, W + 1): if grid[i][j] == "*" and not imosw[i][j] and not imosh[i][j]: return False return True L = list2d(H + 2, W + 2, 0) R = list2d(H + 2, W + 2, 0) U = list2d(H + 2, W + 2, 0) D = list2d(H + 2, W + 2, 0) for i in range(1, H + 1): for j in range(1, W + 1): if grid[i][j] == ".": L[i][j] = 0 else: L[i][j] = L[i][j - 1] + 1 for i in range(1, H + 1): for j in range(W, 0, -1): if grid[i][j] == ".": R[i][j] = 0 else: R[i][j] = R[i][j + 1] + 1 for j in range(1, W + 1): for i in range(1, H + 1): if grid[i][j] == ".": U[i][j] = 0 else: U[i][j] = U[i - 1][j] + 1 for j in range(1, W + 1): for i in range(H, 0, -1): if grid[i][j] == ".": D[i][j] = 0 else: D[i][j] = D[i + 1][j] + 1 for i in range(1, H + 1): for j in range(1, W + 1): if grid[i][j] == "*": check(i, j) for i in range(1, H + 1): for j in range(W + 1): imosw[i][j + 1] += imosw[i][j] for j in range(1, W + 1): for i in range(H + 1): imosh[i + 1][j] += imosh[i][j] if check2(): print(len(ans)) [print(h, w, sz) for h, w, sz in ans] else: print(-1)
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL VAR BIN_OP VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF NONE RETURN VAR NONE FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF NUMBER NUMBER IF VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR STRING VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) c = [] for j in range(n): d = [] s = input() for i in s: d.append(i) c.append(d) a = [] b = [] e = [] g = [] for j in range(n): k = [0] * m e.append(k) for j in range(n): k = [0] * m g.append(k) dpu = [] for j in range(n): k = [0] * m dpu.append(k) dpd = [] for j in range(n): k = [0] * m dpd.append(k) dpl = [] for j in range(n): k = [0] * m dpl.append(k) dpr = [] for j in range(n): k = [0] * m dpr.append(k) for i in range(n): for j in range(m): if c[i][j] == "*": if i > 0: dpu[i][j] += dpu[i - 1][j] + 1 else: dpu[i][j] = 1 if j > 0: dpl[i][j] = dpl[i][j - 1] + 1 else: dpl[i][j] = 1 i = n - 1 while i >= 0: j = m - 1 while j >= 0: if c[i][j] == "*": if i < n - 1: dpd[i][j] += dpd[i + 1][j] + 1 else: dpd[i][j] = 1 if j < m - 1: dpr[i][j] = dpr[i][j + 1] + 1 else: dpr[i][j] = 1 j += -1 i += -1 for i in range(1, n - 1): for j in range(1, m - 1): if c[i][j] == "*": k = min(dpd[i][j] - 1, dpu[i][j] - 1, dpr[i][j] - 1, dpl[i][j] - 1) if k == 0: pass elif k > 0: a.append([i + 1, j + 1, k]) e[i - k][j] += 1 if i + k < n - 1: e[i + k + 1][j] += -1 g[i][j - k] += 1 if j + k < m - 1: g[i][j + k + 1] += -1 for i in range(m): for j in range(1, n): if c[j - 1][i] == "*": e[j][i] += e[j - 1][i] for i in range(n): for j in range(1, m): if c[i][j - 1] == "*": g[i][j] += g[i][j - 1] f = 0 for i in range(n): for j in range(m): if c[i][j] == "*" and e[i][j] <= 0 and g[i][j] <= 0: f = 1 break if f == 1: print(-1) else: print(len(a)) for j in a: print(*j)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING IF VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR STRING VAR VAR VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR BIN_OP VAR NUMBER STRING VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
class StarCell: def __init__(self, row, col, top=None, bot=None, left=None, right=None): self.row = row self.col = col self.covered = False self.top = top self.bot = bot self.left = left self.right = right self._size = None self._size_top = None self._size_bot = None self._size_left = None self._size_right = None def set_adjacents(self, cells): row, col = self.row, self.col self.top = cells.get((row - 1, col), None) self.bot = cells.get((row + 1, col), None) self.left = cells.get((row, col - 1), None) self.right = cells.get((row, col + 1), None) def set_covered(self): size = self.size ctop = self cbot = self cleft = self cright = self for _ in range(size): ctop = ctop.top cbot = cbot.bot cleft = cleft.left cright = cright.right ctop.covered = True cbot.covered = True cleft.covered = True cright.covered = True @property def size_top(self): if not self.top: return 0 if not self._size_top: self._size_top = 1 + self.top.size_top return self._size_top @property def size_bot(self): if not self.bot: return 0 if not self._size_bot: self._size_bot = 1 + self.bot.size_bot return self._size_bot @property def size_left(self): if not self.left: return 0 if not self._size_left: self._size_left = 1 + self.left.size_left return self._size_left @property def size_right(self): if not self.right: return 0 if not self._size_right: self._size_right = 1 + self.right.size_right return self._size_right @property def size(self): if not self._size: self._size = min( [self.size_top, self.size_bot, self.size_left, self.size_right] ) return self._size def __repr__(self): if self.size > 0: return "Star of max size {}".format(self.size) return "Cell covered? {}".format(self.covered) def solve(grid): n, m = len(grid), len(grid[0]) cells = {} for row in range(n): for col in range(m): if grid[row][col] == ".": continue cells[row, col] = StarCell(row, col) for key, val in list(cells.items()): val.set_adjacents(cells) for key, val in list(cells.items()): val.set_covered() ans = [] for key, val in list(cells.items()): if val.size == 0 and not val.covered: return None if val.size > 0: ans.append([val.row + 1, val.col + 1, val.size]) return ans def main(): n, m = list(map(int, input().strip().split())) grid = [list(input().strip()) for _ in range(n)] results = solve(grid) if results is None: print("-1") else: print(len(results)) for result in results: print(*result) def __starting_point(): main() __starting_point()
CLASS_DEF FUNC_DEF NONE NONE NONE NONE ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE ASSIGN VAR NONE FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NONE ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NONE ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NONE ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NONE FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF IF VAR RETURN NUMBER IF VAR ASSIGN VAR BIN_OP NUMBER VAR RETURN VAR VAR FUNC_DEF IF VAR RETURN NUMBER IF VAR ASSIGN VAR BIN_OP NUMBER VAR RETURN VAR VAR FUNC_DEF IF VAR RETURN NUMBER IF VAR ASSIGN VAR BIN_OP NUMBER VAR RETURN VAR VAR FUNC_DEF IF VAR RETURN NUMBER IF VAR ASSIGN VAR BIN_OP NUMBER VAR RETURN VAR VAR FUNC_DEF IF VAR ASSIGN VAR FUNC_CALL VAR LIST VAR VAR VAR VAR RETURN VAR VAR FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL STRING VAR RETURN FUNC_CALL STRING VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER VAR RETURN NONE IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
def main(): n, m = map(int, input().split()) grid = [] for i in range(n): grid.append(input()) visited = set() ans = {} for l in range(1, min(n, m)): for row in range(l, n - l): for col in range(l, m - l): new = set() found = True for col1 in range(col, col - l - 1, -1): new.add((row, col1)) if grid[row][col1] != "*": found = False break if found: for col1 in range(col, col + l + 1): new.add((row, col1)) if grid[row][col1] != "*": found = False break if found: for row1 in range(row, row - l - 1, -1): new.add((row1, col)) if grid[row1][col] != "*": found = False break if found: for row1 in range(row, row + l + 1): new.add((row1, col)) if grid[row1][col] != "*": found = False break if found: if (row + 1, col + 1) not in ans.keys(): ans[row + 1, col + 1] = l else: ans[row + 1, col + 1] = max(ans[row + 1, col + 1], l) for i in new: visited.add(i) for row in range(n): for col in range(m): if grid[row][col] == "*" and (row, col) not in visited: print(-1) return print(len(ans)) for i in ans.keys(): print(i[0], i[1], ans[i]) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
import sys input = sys.stdin.readline def p(board): for row in board: print(*row) n, m = map(int, input().split()) grid = [list(input().strip("\n")) for i in range(n)] up = [[(0) for i in range(m)] for j in range(n)] down = [[(0) for i in range(m)] for j in range(n)] left = [[(0) for i in range(m)] for j in range(n)] right = [[(0) for i in range(m)] for j in range(n)] for i in range(1, n): for j in range(m): if grid[i - 1][j] == "*": up[i][j] = up[i - 1][j] + 1 for i in range(n - 2, -1, -1): for j in range(m): if grid[i + 1][j] == "*": down[i][j] = down[i + 1][j] + 1 for j in range(1, m): for i in range(n): if grid[i][j - 1] == "*": left[i][j] = left[i][j - 1] + 1 for j in range(m - 2, -1, -1): for i in range(n): if grid[i][j + 1] == "*": right[i][j] = right[i][j + 1] + 1 stars = [] for i in range(n): for j in range(m): if grid[i][j] == "*": s = min(up[i][j], down[i][j], right[i][j], left[i][j]) if s: stars.append((i, j, s)) new = [["." for i in range(m)] for j in range(n)] for x, y, s in stars: for i in range(-s, s + 1): new[x + i][y] = "*" new[x][y + i] = "*" if new == grid: print(len(stars)) for i, j, x in stars: print(i + 1, j + 1, x) else: print(-1)
IMPORT ASSIGN VAR VAR FUNC_DEF FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) table = [[0] * (m + 2)] for i in range(n): table.append([0]) s = input() for j in range(m): table[i + 1].append(2 if s[j] == "*" else 0) table[i + 1].append(0) table.append([0] * (m + 2)) dx = [-1, 0, 1, 0] dy = [0, 1, 0, -1] answer = [] for i in range(1, n + 1): for j in range(1, m + 1): if table[i][j] == 0: continue able = True size = 0 while able: size += 1 for k in range(4): if table[i + dx[k] * size][j + dy[k] * size] == 0: able = False size -= 1 if size > 0: table[i][j] = 1 for k in range(1, size + 1): for q in range(4): table[i + dx[q] * k][j + dy[q] * k] = 1 answer.append([i, j, size]) Ok = True for i in range(1, n + 1): for j in range(1, m + 1): if table[i][j] == 2: Ok = False if not Ok: print(-1) else: print(len(answer)) for i in answer: print(*i)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR STRING NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) G = [] L = [[(0) for x in range(m + 2)] for x in range(n + 2)] R = [[(0) for x in range(m + 2)] for x in range(n + 2)] U = [[(0) for x in range(m + 2)] for x in range(n + 2)] D = [[(0) for x in range(m + 2)] for x in range(n + 2)] for i in range(n): s = input() G.append(s) for i in range(n): nm = 0 for j in range(m): if G[i][j] == "*": nm += 1 else: nm = 0 L[i][j] = nm nm = 0 for j in range(m - 1, -1, -1): if G[i][j] == "*": nm += 1 else: nm = 0 R[i][j] = nm for j in range(m): nm = 0 for i in range(n): if G[i][j] == "*": nm += 1 else: nm = 0 U[i][j] = nm nm = 0 for i in range(n - 1, -1, -1): if G[i][j] == "*": nm += 1 else: nm = 0 D[i][j] = nm col = [[(0) for x in range(m + 2)] for x in range(n + 2)] row = [[(0) for x in range(m + 2)] for x in range(n + 2)] ANS = [] for i in range(n): for j in range(m): if G[i][j] == ".": continue ans = min(U[i][j], L[i][j], R[i][j], D[i][j]) - 1 if ans <= 0: continue ANS.append([i + 1, j + 1, ans]) row[i][j - ans] += 1 row[i][j + ans + 1] -= 1 col[i - ans][j] += 1 col[i + ans + 1][j] -= 1 for i in range(n): for j in range(1, m): row[i][j] += row[i][j - 1] for j in range(m): for i in range(1, n): col[i][j] += col[i - 1][j] okay = True for i in range(n): for j in range(m): if G[i][j] == "*" and row[i][j] == 0 and col[i][j] == 0: okay = False if okay: print(len(ANS)) for x in ANS: print(x[0], x[1], x[2]) else: print(-1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = [int(t) for t in input().split()] field = [list(input()) for _ in range(n)] done = [list(map(lambda t: t != "*", line)) for line in field] muls = sum(t.count("*") for t in field) def fit_hor(x): return 0 <= x < m def fit_ver(y): return 0 <= y < n def mark(x, y): global muls global done if not done[x][y]: done[x][y] = True muls -= 1 def get_star_size(i, j): size = 0 i_u = i - 1 i_d = i + 1 j_r = j + 1 j_l = j - 1 if field[i][j] == "*": while ( fit_hor(j_r) and fit_hor(j_l) and fit_ver(i_u) and fit_ver(i_d) and "*" == field[i][j_r] == field[i][j_l] == field[i_d][j] == field[i_u][j] ): mark(i, j_r) mark(i, j_l) mark(i_u, j) mark(i_d, j) size += 1 i_u -= 1 i_d += 1 j_r += 1 j_l -= 1 return size stars = [] for i in range(n): for j in range(m): sz = get_star_size(i, j) if sz > 0: mark(i, j) stars.append((i, j, sz)) if muls > 0: print(-1) else: print(len(stars)) for i, j, s in stars: print(i + 1, j + 1, s)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING VAR VAR FUNC_DEF RETURN NUMBER VAR VAR FUNC_DEF RETURN NUMBER VAR VAR FUNC_DEF IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR STRING WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR STRING VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
def check_size(x_c, y_c): global n, m max_size = min(x_c, m - x_c - 1, y_c, n - y_c - 1) size = 1 while ( size <= max_size and data[y_c][x_c + size] and data[y_c - size][x_c] and data[y_c][x_c - size] and data[y_c + size][x_c] ): size += 1 size -= 1 return size def check_stars(): global n, m for y in range(n): for x in range(m): if data[y][x]: size = check_size(x, y) if size > 0: stars.append([x, y, size]) def check_field(): global n, m for star in stars: x_c = star[0] y_c = star[1] size = star[2] for x in range(x_c - size, x_c + size + 1): data[y_c][x] = False for y in range(y_c - size, y_c + size + 1): data[y][x_c] = False for y in range(n): for x in range(m): if data[y][x]: return False return True n, m = map(int, input().split()) data = [[(False) for j in range(m)] for i in range(n)] for i in range(n): l = input() for j in range(m): data[i][j] = l[j] == "*" stars = [] check_stars() if check_field(): print(len(stars)) for star in stars: print(star[1] + 1, star[0] + 1, star[2]) else: print("-1")
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR FUNC_DEF FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR STRING ASSIGN VAR LIST EXPR FUNC_CALL VAR IF FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
def main(): inp = [] n, m = list(map(int, input().split())) remaining = 0 for _ in range(n): cur_inp = input() inp.append(cur_inp) remaining += cur_inp.count("*") remaining2 = [([True] * m) for _ in range(n)] res = [] for x in range(1, n - 1): for y in range(1, m - 1): if inp[x][y] == "*": last_size = None for size in range(1, min(x + 1, n - x, y + 1, m - y)): if ( inp[x - size][y] == inp[x + size][y] == inp[x][y - size] == inp[x][y + size] == "*" ): for x1, y1 in ( (x - size, y), (x + size, y), (x, y - size), (x, y + size), ): if remaining2[x1][y1]: remaining -= 1 remaining2[x1][y1] = False last_size = size else: break if last_size is not None: if remaining2[x][y]: remaining -= 1 remaining2[x][y] = False res.append((x + 1, y + 1, last_size)) if remaining: print("-1") else: print(len(res)) for x in res: print(*x) main()
FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR NONE FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR IF VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING FOR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR NONE IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = input().split(" ")[:2] n = int(n) m = int(m) orig = [] for _ in range(n): row = input() orig.append(row) copy = [(["."] * m) for _ in range(n)] stars = [] for i in range(n): for j in range(m): curSymbol = orig[i][j] if curSymbol == "*": if ( i > 0 and i < n - 1 and j > 0 and j < m - 1 and orig[i - 1][j] == "*" and orig[i + 1][j] == "*" and orig[i][j + 1] == "*" and orig[i][j - 1] == "*" ): copy[i][j] = "*" radius = 1 while ( i > radius - 1 and i < n - radius and j > radius - 1 and j < m - radius and orig[i - radius][j] == "*" and orig[i + radius][j] == "*" and orig[i][j + radius] == "*" and orig[i][j - radius] == "*" ): copy[i - radius][j] = "*" copy[i + radius][j] = "*" copy[i][j + radius] = "*" copy[i][j - radius] = "*" radius += 1 stars.append((i + 1, j + 1, radius - 1)) if all(orig[i][j] == copy[i][j] for i in range(n) for j in range(m)): print(len(stars)) for star in stars: print(f"{star[0]} {star[1]} {star[2]}") else: print(-1)
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR NUMBER VAR STRING VAR VAR BIN_OP VAR NUMBER STRING VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR STRING ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR STRING VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
import sys n, m = map(int, input().split()) a = [] k = 0 ans = [] for line in sys.stdin: a.append(list(line)) a[-1].pop() for i in range(n): for j in range(m): if a[i][j] == "*": ni = i nj = j p = 0 l = 0 v = 0 vn = 0 while i < n - 1: i += 1 if a[i][j] == "*": p += 1 else: break i = ni while i > 0: i -= 1 if a[i][j] == "*": l += 1 else: break i = ni while j > 0: j -= 1 if a[i][j] == "*": v += 1 else: break j = nj while j < m - 1: j += 1 if a[i][j] == "*": vn += 1 else: break j = nj if min(p, l, v, vn) >= 1: ans.append([i + 1, j + 1, min(p, l, v, vn)]) k += 1 a1 = [] for i in range(n): a1.append(["."] * m) for h in range(k): i = ans[h][0] - 1 j = ans[h][1] - 1 z = ans[h][2] a1[i][j] = "*" for b in range(1, z + 1): a1[i + b][j] = "*" a1[i - b][j] = "*" a1[i][j + b] = "*" a1[i][j - b] = "*" if a1 == a: print(k) for i in ans: print(*i) else: print(-1)
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR WHILE VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
import sys mod = 10**9 + 7 INF = float("inf") def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n, m = inpl() s = [input() for _ in range(n)] chk = [([False] * m) for _ in range(n)] res = [] se = set() for size in range(1, 50)[::-1]: if size * 2 + 1 > n or size * 2 + 1 > m: continue for cy in range(size, n - size): for cx in range(size, m - size): if (cy + 1, cx + 1) in se: continue f = True for dy in range(cy - size, cy + size + 1): if s[dy][cx] == ".": f = False for dx in range(cx - size, cx + size + 1): if s[cy][dx] == ".": f = False if f: res.append([cy + 1, cx + 1, size]) se.add((cy + 1, cx + 1)) for dy in range(cy - size, cy + size + 1): chk[dy][cx] = True for dx in range(cx - size, cx + size + 1): chk[cy][dx] = True for y in range(n): for x in range(m): if s[y][x] == "*" and not chk[y][x]: print(-1) quit() print(len(res)) for l in res: print(*l)
IMPORT ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) s = list() for i in range(n): s.append(list(map(lambda x: 0 if x == "." else 1, *input().split()))) re = list() check_re = [([0] * m) for _ in range(n)] def check(x, y, length): if x + length >= n or y + length >= m or x - length < 0 or y - length < 0: if length > 1: re.append(["{} {} {}".format(x + 1, y + 1, length - 1)]) return tmp = s[x + length][y] + s[x - length][y] + s[x][y + length] + s[x][y - length] if tmp == 4: prin(x, y, length) check(x, y, length + 1) elif length > 1: re.append(["{} {} {}".format(x + 1, y + 1, length - 1)]) def prin(x, y, i): check_re[x][y] = 1 check_re[x + i][y] = 1 check_re[x - i][y] = 1 check_re[x][y + i] = 1 check_re[x][y - i] = 1 for i in range(n): for j in range(m): if s[i][j] == 1: check(i, j, 1) if s == check_re: print(len(re)) for i in re: print(i[0]) else: print(-1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING NUMBER NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) pole = [] metka = [] for i in range(n): pole.append([]) metka.append([]) s = input() for j in range(m): pole[i].append(s[j]) if s[j] == ".": metka[i].append(0) else: metka[i].append(1) k = 0 ans = [] for i in range(n): for j in range(m): if pole[i][j] == "*": e = 0 while ( i - e - 1 >= 0 and j - e - 1 >= 0 and i + e + 1 < n and j + e + 1 < m and pole[i - e - 1][j] == "*" and pole[i][j - e - 1] == "*" and pole[i + e + 1][j] == "*" and pole[i][j + e + 1] == "*" ): e = e + 1 metka[i][j] = 0 metka[i - e][j] = 0 metka[i][j - e] = 0 metka[i + e][j] = 0 metka[i][j + e] = 0 if e != 0: k = k + 1 ans.append((i + 1, j + 1, e)) flag = True for i in range(n): if 1 in metka[i]: flag = False break if not flag: print(-1) else: print(k) for i in range(k): print(ans[i][0], ans[i][1], ans[i][2], end="\n")
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR STRING VAR VAR BIN_OP BIN_OP VAR VAR NUMBER STRING VAR BIN_OP BIN_OP VAR VAR NUMBER VAR STRING VAR VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER STRING
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = [int(i) for i in input().split()] stars = [] directionx = [0, -1, 0, 1] directiony = [1, 0, -1, 0] for i in range(n): stars.append(list(input())) s = 0 f = [([False] * m) for i in range(n)] for i in range(n): for j in range(m): if stars[i][j] == "*": s += 1 anslist = [] ans = 0 for i in range(1, n - 1): for j in range(1, m - 1): if ( stars[i][j] == "*" and stars[i][j - 1] == "*" and stars[i - 1][j] == "*" and stars[i][j + 1] == "*" and stars[i + 1][j] == "*" ): wkf = True count = 0 while wkf: for k in range(4): f[i + directionx[k] * count][j + directiony[k] * count] = True count += 1 for k in range(4): if i + directionx[k] * count >= n: wkf = False break if j + directiony[k] * count >= m: wkf = False break if i + directionx[k] * count < 0: wkf = False break if j + directiony[k] * count < 0: wkf = False break if ( stars[i + directionx[k] * count][j + directiony[k] * count] != "*" ): wkf = False break anslist.append([i + 1, j + 1, count - 1]) ans += 1 if sum([sum(f[i]) for i in range(n)]) == s: print(ans) for i in range(ans): for j in anslist[i]: print(j, end=" ") print() else: print("-1")
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER VAR STRING VAR VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
import sys input = sys.stdin.readline def read(): return list(map(int, input().split())) n, m = read() g = [input() for i in range(n)] mrk = [[(0) for j in range(m)] for i in range(n)] ans = [] for i in range(n): for j in range(m): if g[i][j] == "*": cnt = [0, 0, 0, 0] k = i - 1 while k >= 0 and g[k][j] == "*": k -= 1 cnt[0] += 1 k = i + 1 while k < n and g[k][j] == "*": k += 1 cnt[1] += 1 k = j - 1 while k >= 0 and g[i][k] == "*": k -= 1 cnt[2] += 1 k = j + 1 while k < m and g[i][k] == "*": k += 1 cnt[3] += 1 mn = min(cnt) if mn: mrk[i][j] = 1 for k in range(1, mn + 1): mrk[i - k][j] = 1 mrk[i + k][j] = 1 mrk[i][j - k] = 1 mrk[i][j + k] = 1 ans.append([i + 1, j + 1, mn]) for i in range(n): for j in range(m): if g[i][j] == "*" and not mrk[i][j]: print(-1) quit() print(len(ans)) for a, b, c in ans: print(a, b, c)
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR STRING VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) num = [] used = [] for i in range(n): num.append(input()) used.append([False] * m) ans = [] for i in range(1, n - 1): for j in range(1, m - 1): if num[i][j] == "*": d1 = 0 d2 = 0 d3 = 0 d4 = 0 for x in range(j + 1, m): if num[i][x] == ".": d1 = x - j - 1 break else: d1 = m - j - 1 for x in range(j - 1, -1, -1): if num[i][x] == ".": d2 = abs(j - x - 1) break else: d2 = j for y in range(i + 1, n): if num[y][j] == ".": d3 = y - i - 1 break else: d3 = n - i - 1 for y in range(i - 1, -1, -1): if num[y][j] == ".": d4 = abs(i - y - 1) break else: d4 = i dist = min(d1, d2, d3, d4) if dist != 0: ans.append([i + 1, j + 1, dist]) for x in range(j - dist, j + dist + 1): used[i][x] = True for y in range(i - dist, i + dist + 1): used[y][j] = True fl = True for i in range(n): for j in range(m): if num[i][j] == "*" and not used[i][j]: fl = False if not fl: print(-1) else: print(len(ans)) for i in range(len(ans)): print(*ans[i])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) sky = [0] * (n + 1) for i in range(n): sky[i] = list(input()) + ["."] sky[n] = ["."] * m used = [([False] * m) for i in range(n)] ans = [] for i in range(n): for j in range(m): if sky[i][j] == ".": continue ln = 1 while ( sky[i - ln][j] == "*" and sky[i + ln][j] == "*" and sky[i][j - ln] == "*" and sky[i][j + ln] == "*" ): used[i - ln][j] = used[i + ln][j] = used[i][j - ln] = used[i][j + ln] = True ln += 1 if ln > 1: used[i][j] = True ans += [[i + 1, j + 1, ln - 1]] for i in range(n): for j in range(m): if sky[i][j] == "*" and not used[i][j]: print(-1) exit(0) print(len(ans)) for i in range(len(ans)): print(*ans[i])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR LIST STRING ASSIGN VAR VAR BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR LIST LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
def findStar(ar, i, j, n, m): size = 1 newStars = 0 while True: if ( j - size > -1 and j + size < m and i - size > -1 and i + size < n and ar[i][j - size] > 0 and ar[i][j + size] > 0 and ar[i - size][j] > 0 and ar[i + size][j] > 0 ): if ar[i][j - size] == 1: newStars += 1 ar[i][j - size] += 1 if ar[i][j + size] == 1: newStars += 1 ar[i][j + size] += 1 if ar[i - size][j] == 1: newStars += 1 ar[i - size][j] += 1 if ar[i + size][j] == 1: newStars += 1 ar[i + size][j] += 1 if ar[i][j] == 1: newStars += 1 ar[i][j] += 1 size += 1 else: return ar, size - 1, newStars n, m = map(int, input().split()) mat = [] ar = [] for _ in range(n): l = list(input()) mat.append(l) ar.append([0] * m) starCount = 0 for i in range(n): for j in range(m): if mat[i][j] == "*": ar[i][j] = 1 starCount += 1 out = [] countStars = 0 for i in range(1, n - 1): for j in range(1, m - 1): if ar[i][j] > 0: ar, vals, newStars = findStar(ar, i, j, n, m) if vals > 0: out.append([i + 1, j + 1, vals]) countStars += newStars if starCount == countStars: print(len(out)) for row in out: print(row[0], row[1], row[2]) else: print(-1)
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER RETURN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
def main(): n, m = map(int, input().split()) ll = [(c == "*") for _ in range(n) for c in input()] nm = n * m RLUD = [ *[range(i, i + m) for i in range(0, nm, m)], *[range(i, nm, m) for i in range(m)], ] cc = [1000] * nm for f in (True, False): for r in RLUD: v = 0 for i in r: if ll[i]: v += 1 if cc[i] > v: cc[i] = v else: v = cc[i] = 0 if f: ll.reverse() cc.reverse() cc = [(c if c != 1 else 0) for c in cc] for f in (True, False): for r in RLUD: v = 0 for i in r: if v > cc[i]: v -= 1 else: v = cc[i] if v: ll[i] = False if f: ll.reverse() cc.reverse() if any(ll): print(-1) else: res = [] for i, c in enumerate(cc): if c: res.append(f"{i // m + 1} {i % m + 1} {c - 1}") print(len(res), "\n".join(res), sep="\n") main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST FUNC_CALL VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR VAR FOR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR ASSIGN VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL STRING VAR STRING EXPR FUNC_CALL VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
def go(): n, m = [int(i) for i in input().split(" ")] grid = [] count = 0 for _ in range(n): l = [i for i in input()] count += l.count("*") grid.append(l) visited = set() stars = set() def x(i, j): low = i - 1 high = i + 1 while -1 < low < n and -1 < high < n and grid[low][j] == grid[high][j] == "*": low -= 1 high += 1 low += 1 high -= 1 left = j - 1 right = j + 1 while ( -1 < left < m and -1 < right < m and grid[i][left] == grid[i][right] == "*" ): left -= 1 right += 1 left += 1 right -= 1 z = min((high - low) // 2, (right - left) // 2) if z > 0: stars.add((i + 1, j + 1, z)) visited.add((i, j)) for k in range(z + 1): visited.add((i, j - k)) visited.add((i, j + k)) visited.add((i - k, j)) visited.add((i + k, j)) for i in range(n): for j in range(m): if grid[i][j] == "*": x(i, j) if len(visited) != count: print(-1) else: print(len(stars)) for star in stars: print(" ".join(str(i) for i in star)) go()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE NUMBER VAR VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR STRING VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
R = lambda: map(int, input().split()) n, m = R() g = [input() for _ in range(n)] f = [([0] * m) for i in range(n)] res = [] for i in range(n): for j in range(m): if g[i][j] == "*": d = 1 while ( i >= d and i + d < n and j >= d and j + d < m and g[i - d][j] == g[i + d][j] == g[i][j - d] == g[i][j + d] == "*" ): f[i][j] = f[i - d][j] = f[i + d][j] = f[i][j - d] = f[i][j + d] = 1 d += 1 d -= 1 if d >= 1: res.append([i + 1, j + 1, d]) for i in range(n): for j in range(m): if g[i][j] == "*" and not f[i][j]: print(-1) exit(0) print(len(res)) for r in res: print(" ".join(map(str, r)))
ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
import sys n, m = map(int, input().split()) a = [[c for c in l.strip()] for l in sys.stdin] ans = [] for i in range(n): for j in range(m): b = a[i][j] for k in range(1, 101): if i > k - 1 and i < n - k and j > k - 1 and j < m - k and b == "*": if ( a[i + k][j] == "*" and a[i - k][j] == "*" and a[i][j + k] == "*" and a[i][j - k] == "*" ): if k == 1: ans.append([i + 1, j + 1, k]) else: ans.pop() ans.append([i + 1, j + 1, k]) else: break c = [(["."] * m) for i in range(n)] for i in range(len(ans)): d, e, f = ans[i] d -= 1 e -= 1 c[d][e] = "*" for j in range(1, f + 1): c[d + j][e] = "*" c[d - j][e] = "*" c[d][e + j] = "*" c[d][e - j] = "*" if c == a: print(len(ans)) for i in range(len(ans)): a = map(str, ans[i]) print(" ".join(a)) else: print(-1)
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR STRING IF VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST STRING VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
w = [int(x) for x in input().split()] n = w[0] m = w[1] a = [["." for i in range(m)] for j in range(n)] s = [list(input()) for i in range(n)] res = [] for i in range(1, n - 1): for j in range(1, m - 1): if ( s[i][j] == "*" and s[i - 1][j] == "*" and s[i + 1][j] == "*" and s[i][j - 1] == "*" and s[i][j + 1] == "*" ): x = 1 while ( i - x >= 0 and i + x < n and j - x >= 0 and j + x < m and s[i + x][j] == "*" and s[i - x][j] == "*" and s[i][j - x] == "*" and s[i][j + x] == "*" ): a[i][j], a[i - x][j], a[i][j + x], a[i + x][j], a[i][j - x] = ( "*", "*", "*", "*", "*", ) x += 1 res.append([i + 1, j + 1, x - 1]) if a != s: print(-1) else: print(len(res), end=" ") for i in res: print(end="\n") print(i[0], " ", i[1], " ", i[2], end=" ")
ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING VAR BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR NUMBER VAR STRING VAR VAR BIN_OP VAR NUMBER STRING VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR STRING STRING STRING STRING STRING VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR NUMBER STRING VAR NUMBER STRING VAR NUMBER STRING
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
io = input().split() n = int(io[0]) m = int(io[1]) arr = [] def analitic(y, x): global n, m, arr maxValue = min(y, m - x - 1, n - y - 1, x) tMax = rMax = bMax = lMax = 0 for i in range(maxValue): if arr[y - i - 1][x] == ".": tMax = i break else: tMax = i + 1 for i in range(maxValue): if arr[y][x + i + 1] == ".": rMax = i break else: rMax = i + 1 for i in range(maxValue): if arr[y + i + 1][x] == ".": bMax = i break else: bMax = i + 1 for i in range(maxValue): if arr[y][x - i - 1] == ".": lMax = i break else: lMax = i + 1 return min(tMax, rMax, bMax, lMax) def drawChar(currentCahr): if currentCahr == 0: return "*" return currentCahr def draw(y, x, size): global arr for i in range(size): arr[y - i - 1][x] = drawChar(arr[y - i - 1][x]) for i in range(size): arr[y][x + i + 1] = drawChar(arr[y][x + i + 1]) for i in range(size): arr[y + i + 1][x] = drawChar(arr[y + i + 1][x]) for i in range(size): arr[y][x - i - 1] = drawChar(arr[y][x - i - 1]) for i in range(n): arr.append(list(input())) for i in range(n): for j in range(m): if arr[i][j] == ".": continue arr[i][j] = analitic(i, j) res = [] for i in range(n): for j in range(m): if arr[i][j] != "." and arr[i][j] != "*" and arr[i][j] != 0: res.append(str(i + 1) + " " + str(j + 1) + " " + str(arr[i][j])) draw(i, j, arr[i][j]) for i in range(n): for j in range(m): if arr[i][j] == 0: print(-1) exit() print(len(res)) for i in res: print(i)
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN STRING RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR STRING VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
def i_ints(): return map(int, input().split()) def stars_to_the_left(s): res = [] n = len(s) l = 0 while l < n: r = s.find("*", l) if r == -1: r = n res.extend([0] * (r - l)) l = s.find(".", r) if l == -1: l = n res.extend(range(1, l - r + 1)) return res def main(): n, m = i_ints() global cols, ups rows = [input() for i in range(n)] raveled = "".join(rows) cols = [raveled[i::m] for i in range(m)] lefts = [stars_to_the_left(row) for row in rows] rights = [stars_to_the_left(row[::-1])[::-1] for row in rows] downs = [stars_to_the_left(col) for col in cols] ups = [stars_to_the_left(col[::-1])[::-1] for col in cols] lr = [] for l in lefts: lr.extend(l) rr = [] for r in rights: rr.extend(r) dr = [0] * (n * m) for i, d in enumerate(downs): dr[i::m] = d ur = [0] * (n * m) for i, u in enumerate(ups): ur[i::m] = u res = [] todo = rr[:] for i, lengths in enumerate(zip(lr, rr, dr, ur)): length = min(lengths) - 1 if length > 0: x, y = divmod(i, m) res.append((x + 1, y + 1, length)) todo[i - length * m : i + length * m + m : m] = todo[ i - length : i + length + 1 ] = [0] * (2 * length + 1) if max(todo) > 0: print(-1) else: print(len(res)) for r in res: print(*r) main()
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR IF VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING VAR IF VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = [int(x) for x in input().split()] L = [] for _ in range(n): L.extend([i for i in input()]) for i in range(n * m): if L[i] == ".": L[i] = 0 else: L[i] = 1 stars = [] for i in range(n * m): l = 0 y = i // m x = i % m if L[i] == 1: while True: if y + l != n - 1 and y - l != 0 and x - l != 0 and x + l != m - 1: l += 1 if L[i + l] * L[i - l] * L[i - l * m] * L[i + l * m] == 0: l -= 1 break else: break if l > 0: stars.append((i, l)) T = [0] * (n * m) for s in stars: T[s[0]] = 1 for l in range(1, s[1] + 1): T[s[0] + l] = 1 T[s[0] - l] = 1 T[s[0] - l * m] = 1 T[s[0] + l * m] = 1 if T == L: print(len(stars)) for s in stars: print(1 + s[0] // m, 1 + s[0] % m, s[1]) else: print(-1)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR NUMBER WHILE NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) T = [[] for i in range(n)] for i in range(n): a = list(input()) T[i] = a S = [([0] * m) for i in range(n)] for i in range(n): for j in range(m): if T[i][j] == "*": S[i][j] = 1 rec = [] for i in range(n): for j in range(m): if ( 1 <= i < n - 1 and 1 <= j < m - 1 and T[i][j] == "*" and T[i - 1][j] == "*" and T[i][j - 1] == "*" and T[i + 1][j] == "*" and T[i][j + 1] == "*" ): S[i][j] = 0 S[i - 1][j] = 0 S[i][j - 1] = 0 S[i + 1][j] = 0 S[i][j + 1] = 0 k = 2 while True: if not (0 <= i - k and i + k < n and 0 <= j - k and j + k < m): break if ( T[i - k][j] == "*" and T[i][j - k] == "*" and T[i + k][j] == "*" and T[i][j + k] == "*" ): S[i - k][j] = 0 S[i][j - k] = 0 S[i + k][j] = 0 S[i][j + k] = 0 k += 1 else: break rec.append((i + 1, j + 1, k - 1)) q = 0 for i in range(n): for j in range(m): q += S[i][j] if q == 0: print(len(rec)) for i in range(len(rec)): print("{} {} {}".format(rec[i][0], rec[i][1], rec[i][2])) else: print(-1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR STRING VAR BIN_OP VAR NUMBER VAR STRING VAR VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER VAR STRING VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = list(map(int, input().split())) pole = [] unfitted = [] def star_fits(x, y, r): if x - r >= 0 and x + r < m and y - r >= 0 and y + r < n: res = True for k in range(x - r, x + r + 1): if pole[y][k] != "*": res = False for k in range(y - r, y + r + 1): if pole[k][x] != "*": res = False else: return False return res def get_max_r(x, y): r = 1 while x - r >= 0 and x + r < m and y - r >= 0 and y + r < n: if ( pole[y][x + r] == "*" and pole[y][x - r] == "*" and pole[y + r][x] == "*" and pole[y - r][x] == "*" ): r += 1 else: return r - 1 return r - 1 def mark_star(x, y, r): if x - r >= 0 and x + r < m and y - r >= 0 and y + r < n: for k in range(x - r, x + r + 1): unfitted[y][k] = False for k in range(y - r, y + r + 1): unfitted[k][x] = False for i in range(n): pole.append(input().strip()[:m]) unfitted.append([True] * m) fin_res = [] for x in range(m): for y in range(n): if pole[y][x] == "*": r = get_max_r(x, y) if r > 0: mark_star(x, y, r) fin_res.append((y + 1, x + 1, r)) for x in range(m): for y in range(n): if pole[y][x] == "*" and unfitted[y][x]: print(-1) exit() print(len(fin_res)) for t in fin_res: print(*t)
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR NUMBER RETURN NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR NUMBER RETURN BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
from sys import stdin, stdout def main(): n, m = map(int, stdin.readline().split()) A = [list(stdin.readline()[:-1]) for _ in range(n)] B = [[(False) for _ in range(m)] for __ in range(n)] def star(i, j, x): if ( i - x >= 0 and i + x < n and j - x >= 0 and j + x < m and A[i + x][j] == "*" and A[i - x][j] == "*" and A[i][j + x] == "*" and A[i][j - x] == "*" ): B[i + x][j] = True B[i - x][j] = True B[i][j + x] = True B[i][j - x] = True return True return False R = [] for i in range(n): for j in range(m): if A[i][j] == "*": x = 1 while star(i, j, x): x += 1 if x > 1: B[i][j] = True R.append([str(i + 1), str(j + 1), str(x - 1)]) for i in range(n): for j in range(m): if B[i][j] != (A[i][j] == "*"): stdout.write("-1") exit(0) stdout.write("{}\n".format(len(R))) for X in R: stdout.write("{} {} {}\n".format(X[0], X[1], X[2])) main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = list(map(int, input().split())) used = [([True] * m) for i in range(n)] Pole = [0] * n M = [] for i in range(n): Pole[i] = list(input()) for i in range(n): for g in range(m): if Pole[i][g] == "*": k = 0 while i - k - 1 >= 0 and i + k + 1 < n and g - k - 1 >= 0 and g + k + 1 < m: if ( Pole[i - k - 1][g] == "*" and Pole[i + k + 1][g] == "*" and Pole[i][g - k - 1] == "*" and Pole[i][g + k + 1] == "*" ): used[i - k - 1][g] = False used[i + k + 1][g] = False used[i][g - k - 1] = False used[i][g + k + 1] = False k += 1 continue break if k != 0: used[i][g] = False M.append([i + 1, g + 1, k]) for i in range(n): for g in range(m): if Pole[i][g] == "*": if used[i][g]: print(-1) break else: continue break else: print(len(M)) for i in range(len(M)): print(*M[i])
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER VAR STRING VAR BIN_OP BIN_OP VAR VAR NUMBER VAR STRING VAR VAR BIN_OP BIN_OP VAR VAR NUMBER STRING VAR VAR BIN_OP BIN_OP VAR VAR NUMBER STRING ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
import sys n, m = map(int, input().split()) s = [list(input()) for i in range(n)] u = [[(-1) for i in range(m)] for j in range(n)] d = [[(-1) for i in range(m)] for j in range(n)] l = [[(-1) for i in range(m)] for j in range(n)] r = [[(-1) for i in range(m)] for j in range(n)] for i in range(m): acum = 0 for j in range(n): if s[j][i] == ".": acum = 0 else: acum += 1 u[j][i] = acum for i in range(m): acum = 0 for j in range(n - 1, -1, -1): if s[j][i] == ".": acum = 0 else: acum += 1 d[j][i] = acum for i in range(n): acum = 0 for j in range(m): if s[i][j] == ".": acum = 0 else: acum += 1 l[i][j] = acum for i in range(n): acum = 0 for j in range(m - 1, -1, -1): if s[i][j] == ".": acum = 0 else: acum += 1 r[i][j] = acum ans = [] t1 = [[(0) for i in range(m)] for j in range(n)] t2 = [[(0) for i in range(m)] for j in range(n)] for i in range(n): for j in range(m): d1 = min(l[i][j], r[i][j], u[i][j], d[i][j]) - 1 if d1 > 0: ans.append([i + 1, j + 1, d1]) t1[i + d1][j] += 1 t1[i - d1][j] -= 1 t2[i][j - d1] += 1 t2[i][j + d1] -= 1 dp = [["." for i in range(m)] for j in range(n)] for i in range(n): acum = 0 for j in range(m): acum += t2[i][j] if acum != 0 or t2[i][j] != 0: dp[i][j] = "*" for i in range(m): acum = 0 for j in range(n): acum += t1[j][i] if acum != 0 or t1[j][i] != 0: dp[j][i] = "*" if dp != s: print(-1) sys.exit() print(len(ans)) for i in ans: print(*i)
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR STRING ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR STRING IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = [int(x) for x in input().split()] grid = [[x for x in input()] for _ in range(n)] star_mem = {} astr_num = set() def l_0(x): return x < 1 def astr_size(x, y, size): for i in range(y, y + size + 1, 1): astr_num.add((x, i)) for i in range(y, y - size - 1, -1): astr_num.add((x, i)) for i in range(x, x + size + 1, 1): astr_num.add((i, y)) for i in range(x, x - size - 1, -1): astr_num.add((i, y)) def is_star(grid, x, y): left, right, uper, lower = -1, -1, -1, -1 for i in range(y, m, 1): if (x, y) in star_mem: left += star_mem[x, y][0] break if grid[x][i] == "*": left += 1 else: break if l_0(left): return False, 0 for i in range(y, -1, -1): if (x, y) in star_mem: right += star_mem[x, y][1] break if grid[x][i] == "*": right += 1 else: break if l_0(right): return False, 0 for i in range(x, n, 1): if (x, y) in star_mem: uper += star_mem[x, y][2] break if grid[i][y] == "*": uper += 1 else: break if l_0(uper): return False, 0 for i in range(x, -1, -1): if (x, y) in star_mem: lower += star_mem[x, y][3] break if grid[i][y] == "*": lower += 1 else: break if l_0(lower): return False, 0 star_mem[x, y] = left, right, uper, lower size = min(left, right, uper, lower) if size > 0: return True, size return False, 0 solution = [] uni_astr = 0 for x in range(n): for y in range(m): if grid[x][y] == "*": uni_astr += 1 con, size = is_star(grid, x, y) if con: astr_size(x, y, size) solution.append((x + 1, y + 1, size)) if uni_astr == len(astr_num): print(len(solution)) for i in solution: print(*i) else: print(-1)
ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_DEF RETURN VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR RETURN NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR RETURN NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR RETURN NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER IF FUNC_CALL VAR VAR RETURN NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER VAR RETURN NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
def possible(i, j): count = 0 x = 10**18 for k in range(j + 1, m): if grid[i][k] == "*": count += 1 else: break x = min(x, count) count = 0 for k in range(j - 1, -1, -1): if grid[i][k] == "*": count += 1 else: break x = min(x, count) count = 0 for k in range(i + 1, n): if grid[k][j] == "*": count += 1 else: break x = min(x, count) count = 0 for k in range(i - 1, -1, -1): if grid[k][j] == "*": count += 1 else: break x = min(x, count) if x == 0: return -1 for k in range(i - x, i + x + 1): done[k, j] = 1 for k in range(j - x, j + x + 1): done[i, k] = 1 return x n, m = map(int, input().split()) grid = [] l = {} for i in range(n): grid.append(input()) for j in range(m): if grid[-1][j] == "*": l[i, j] = 1 done = {} c = {} for i in range(n): for j in range(m): if grid[i][j] == "*": x = possible(i, j) if x != -1: c[i, j] = x if len(l) == len(done): break if len(l) != len(done): print(-1) exit() print(len(c)) for i in c: print(i[0] + 1, i[1] + 1, c[i])
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
def check(x, y, fd, stars, n, m): ln = 1 while y - ln > -1 and x - ln > -1 and y + ln < m and x + ln < n: flag = True if fd[x - ln][y] == ".": flag = False if fd[x + ln][y] == ".": flag = False if fd[x][y - ln] == ".": flag = False if fd[x][y + ln] == ".": flag = False if flag: fd[x - ln] = fd[x - ln][:y] + "+" + fd[x - ln][y + 1 :] fd[x + ln] = fd[x + ln][:y] + "+" + fd[x + ln][y + 1 :] fd[x] = fd[x][: y - ln] + "+" * (ln + ln + 1) + fd[x][y + ln + 1 :] ln += 1 elif ln > 1: stars.append(str(x + 1) + " " + str(y + 1) + " " + str(ln - 1)) return else: return if ln - 1 > 0: stars.append(str(x + 1) + " " + str(y + 1) + " " + str(ln - 1)) n, m = map(int, input().split()) stars = [] fd = [] for i in range(n): fd.append(input()) final = False for i in range(1, n): for j in range(1, m): if fd[i][j] != ".": isIsland = False if ( fd[i - 1][j] == "." and fd[i + 1][j] == "." and fd[i][j - 1] == "." and fd[i][j + 1] == "." ): isIsland = True if isIsland: final = True break else: check(i, j, fd, stars, n, m) if final: print(-1) break if not final: for i in range(n): for j in range(m): if fd[i][j] == "*": final = True break if final: print(-1) break if not final: print(len(stars)) for i in stars: print(i)
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR NUMBER IF VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP STRING BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER RETURN RETURN IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR NUMBER VAR STRING VAR VAR BIN_OP VAR NUMBER STRING VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
def zvezda(r, c, dlina): global s, resA, d for i in range(r - dlina, r + dlina + 1): if s[i][c] == ".": return False for i in range(c - dlina, c + dlina + 1): if s[r][i] == ".": return False for i in range(r - dlina, r + dlina + 1): s[i] = s[i][:c] + "1" + s[i][c + 1 :] s[r] = s[r][: c - dlina] + "1" * (2 * dlina + 1) + s[r][c + dlina + 1 :] if r not in d: d[r] = {} d[r][c] = dlina resA.append(str(r + 1) + " " + str(c + 1) + " " + str(dlina)) return True def checkZvezdy(dlina): global s, resA, d for stroka in range(dlina, n - dlina): for column in range(dlina, m - dlina): if stroka not in d or column not in d[stroka]: zvezda(stroka, column, dlina) n, m = map(int, input().split()) s = [] for i in range(n): s.append(input()) resA = [] d = {} for dlina in range((min(n, m) - 1) // 2, 0, -1): checkZvezdy(dlina) for i in range(n): for j in range(m): if s[i][j] == "*": exit(print(-1)) print(len(resA)) for i in range(len(resA)): print(resA[i])
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR STRING RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR STRING RETURN NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP STRING BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR DICT ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = input().split() n = int(n) m = int(m) lst = [([0] * m) for i in range(n)] rec = [([0] * m) for i in range(n)] fin = [([0] * m) for i in range(n)] ans = 0 cnt = 0 for i in range(n): tmp = input() for j, x in enumerate(tmp): if x == "*": lst[i][j] = 1 for i in range(n): for j in range(m): if lst[i][j] == 1 and i > 0 and j > 0 and i < n - 1 and j < m - 1: tmp = min(i, j, n - 1 - i, m - 1 - j) for k in range(tmp, 0, -1): flag = True for x in range(1, k + 1): if ( lst[i][j - x] == 0 or lst[i][j + x] == 0 or lst[i - x][j] == 0 or lst[i + x][j] == 0 ): flag = False if flag: fin[i][j] = k break for i in range(n): for j in range(m): if fin[i][j] > 0: tmp = fin[i][j] ans += 1 cnt += 1 + tmp * 4 rec[i][j] = 1 for x in range(tmp + 1): rec[i][j + x] = 1 rec[i][j - x] = 1 rec[i - x][j] = 1 rec[i + x][j] = 1 if rec != lst: print(-1) else: print(ans) for i in range(n): for j in range(m): if fin[i][j] > 0: print(i + 1, j + 1, fin[i][j])
ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
import sys input = lambda: sys.stdin.readline().rstrip() h, w = map(int, input().split()) s = ( [list("." * (w + 2))] + [list("." + input() + ".") for _ in range(h)] + [list("." * (w + 2))] ) b = [([0] * (w + 2)) for _ in range(h + 2)] c = [([0] * (w + 2)) for _ in range(h + 2)] for i in range(1, h + 2): for j in range(1, w + 2): if s[i][j] == "*": b[i][j] = b[i - 1][j] + 1 c[i][j] = c[i][j - 1] + 1 for i in range(h, -1, -1): for j in range(w, -1, -1): if s[i][j] == "*": b[i][j] = min(b[i][j], b[i + 1][j] + 1) c[i][j] = min(c[i][j], c[i][j + 1] + 1) ans = [] for i in range(1, h + 1): for j in range(1, w + 1): t = min(b[i][j], c[i][j]) - 1 if t > 0: ans.append((i, j, t)) b = [([0] * (w + 2)) for _ in range(h + 2)] c = [([0] * (w + 2)) for _ in range(h + 2)] for i, j, t in ans: b[i - t][j] += 1 b[i + t + 1][j] -= 1 c[i][j - t] += 1 c[i][j + t + 1] -= 1 for i in range(h + 1): for j in range(w + 1): b[i + 1][j] += b[i][j] c[i][j + 1] += c[i][j] if i != 0 and j != 0: if (b[i][j] + c[i][j] > 0) != (s[i][j] == "*"): print(-1) exit() print(len(ans)) for i in ans: print(*i)
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING VAR FUNC_CALL VAR VAR LIST FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
N, M = map(int, input().split()) L = [] for a in range(N): L.append(list(input())) ANS = [] for i in range(N): for j in range(M): if L[i][j] == "*" or L[i][j] == "-": k = 1 l = min(i, j, N - 1 - i, M - 1 - j) while k <= l: if ( (L[i + k][j] == "*" or L[i + k][j] == "-") and (L[i][j + k] == "*" or L[i][j + k] == "-") and (L[i - k][j] == "*" or L[i - k][j] == "-") and (L[i][j - k] == "*" or L[i][j - k] == "-") ): L[i][j] = "-" L[i + k][j] = "-" L[i - k][j] = "-" L[i][j + k] = "-" L[i][j - k] = "-" k += 1 else: break if k > 1: ANS.append((i + 1, j + 1, k - 1)) f = True for a in L: if "*" in a: f = False break if f: print(len(ANS)) for a in ANS: print(" ".join(map(str, a))) else: print(-1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR VAR IF VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR STRING VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF STRING VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) c = [] for j in range(n): d = [] s = input() for i in s: d.append(i) c.append(d) a = [] b = [] for j in range(n): a.append([0] * m) for i in range(1, n - 1): for j in range(1, m - 1): if c[i][j] == "*": p = i - 1 x = 0 while p >= 0: if c[p][j] == "*": x += 1 else: break p += -1 p = i + 1 y = 0 while p < n: if c[p][j] == "*": y += 1 else: break p += 1 p = j + 1 z = 0 while p < m: if c[i][p] == "*": z += 1 else: break p += 1 p = j - 1 e = 0 while p >= 0: if c[i][p] == "*": e += 1 else: break p += -1 x = min(x, y, z, e) if x > 0: b.append([i + 1, j + 1, x]) a[i][j] = 1 p = i - 1 while p >= i - x: a[p][j] = 1 p += -1 p = i + 1 y = 0 while p <= i + x: a[p][j] = 1 p += 1 p = j + 1 z = 0 while p <= j + x: a[i][p] = 1 p += 1 p = j - 1 e = 0 while p >= j - x: a[i][p] = 1 p += -1 f = 0 for i in range(n): for j in range(m): if c[i][j] == "*" and a[i][j] == 0: f = 1 break if f == 1: print(-1) else: print(len(b)) for j in b: print(*j)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) mat = [] for i in range(n): mat.append(list(map(int, input().replace("*", "1").replace(".", "0")))) ver, hor = [[(0) for i in range(m)] for j in range(n)], [ [(0) for i in range(m)] for j in range(n) ] dp = [[[(0) for i in range(4)] for j in range(m)] for k in range(n)] for i in range(1, n): for j in range(1, m): x, y = n - i - 1, m - j - 1 if mat[i][j] == 1: dp[i][j][0] = max(dp[i][j - 1][0], mat[i][j - 1]) + 1 dp[i][j][1] = max(dp[i - 1][j][1], mat[i - 1][j]) + 1 if mat[x][y] == 1: dp[x][y][2] = max(dp[x][y + 1][2], mat[x][y + 1]) + 1 dp[x][y][3] = max(dp[x + 1][y][3], mat[x + 1][y]) + 1 stars = [] for i in range(1, n - 1): for j in range(1, m - 1): if mat[i][j] == 1: s = min(dp[i][j]) - 1 if s > 0: stars.append((i + 1, j + 1, s)) ver[i - s][j] += 1 if i + s + 1 < n: ver[i + s + 1][j] -= 1 hor[i][j - s] += 1 if j + s + 1 < m: hor[i][j + s + 1] -= 1 for i in range(1, n): for j in range(1, m): ver[i][j] += ver[i - 1][j] hor[i][j] += hor[i][j - 1] chk = True for i in range(n): for j in range(m): if mat[i][j] and max(ver[i][j], hor[i][j]) <= 0: chk = False break if chk: print(len(stars)) for i in stars: print(*i) else: print(-1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING STRING STRING STRING ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER VAR VAR BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) arr = [] for i in range(n): arr.append(list(input())) vis = {} ans = [] for i in range(1, n - 1): for j in range(1, m - 1): if arr[i][j] == "*": if ( arr[i + 1][j] == "*" and arr[i - 1][j] == "*" and arr[i][j + 1] == "*" and arr[i][j - 1] == "*" ): w, x, y, z = [i + 1, j], [i - 1, j], [i, j + 1], [i, j - 1] vis[i, j] = 1 while True: if w[0] >= n or w[0] < n and arr[w[0]][w[1]] != "*": break else: w[0] += 1 if x[0] < 0 or x[0] >= 0 and arr[x[0]][x[1]] != "*": break else: x[0] -= 1 if y[1] >= m or y[1] < m and arr[y[0]][y[1]] != "*": break else: y[1] += 1 if z[1] < 0 or z[1] >= 0 and arr[z[0]][z[1]] != "*": break else: z[1] -= 1 vis[w[0] - 1, w[1]] = 1 vis[x[0] + 1, x[1]] = 1 vis[y[0], y[1] - 1] = 1 vis[z[0], z[1] + 1] = 1 ans.append( [ i + 1, j + 1, min(w[0] - i - 1, i - x[0] - 1, y[1] - j - 1, j - z[1] - 1), ] ) flag = True for i in range(n): for j in range(m): if arr[i][j] == "*" and (i, j) not in vis: flag = False break if not flag: print(-1) else: print(len(ans)) for i in range(len(ans)): print(*ans[i])
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR STRING IF VAR BIN_OP VAR NUMBER VAR STRING VAR BIN_OP VAR NUMBER VAR STRING VAR VAR BIN_OP VAR NUMBER STRING VAR VAR BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR VAR LIST BIN_OP VAR NUMBER VAR LIST BIN_OP VAR NUMBER VAR LIST VAR BIN_OP VAR NUMBER LIST VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER STRING VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER STRING VAR NUMBER NUMBER IF VAR NUMBER VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER STRING VAR NUMBER NUMBER IF VAR NUMBER NUMBER VAR NUMBER NUMBER VAR VAR NUMBER VAR NUMBER STRING VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = map(int, input().split()) g = [[*input()] for _ in range(n)] c = [[(0) for _ in range(m)] for _ in range(n)] for i in range(n): v = 0 for j in range(m): v = (v + 1) * (g[i][j] == "*") c[i][j] = v v = 0 for j in range(m - 1, -1, -1): v = (v + 1) * (g[i][j] == "*") c[i][j] = min(c[i][j], v) for j in range(m): v = 0 for i in range(n): v = (v + 1) * (g[i][j] == "*") c[i][j] = min(c[i][j], v) v = 0 for i in range(n - 1, -1, -1): v = (v + 1) * (g[i][j] == "*") c[i][j] = min(c[i][j], v) for i in range(n): for j in range(m): if c[i][j] == 1: c[i][j] = 0 for i in range(n): v = 0 for j in range(m): v = max(v - 1, c[i][j]) if v: g[i][j] = "." v = 0 for j in range(m - 1, -1, -1): v = max(v - 1, c[i][j]) if v: g[i][j] = "." for j in range(m): v = 0 for i in range(n): v = max(v - 1, c[i][j]) if v: g[i][j] = "." for i in range(n - 1, -1, -1): v = max(v - 1, c[i][j]) if v: g[i][j] = "." if all(g[i][j] == "." for i in range(n) for j in range(m)): r = [(i + 1, j + 1, c[i][j] - 1) for i in range(n) for j in range(m) if c[i][j]] print(len(r)) for t in r: print(*t) else: print(-1)
ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR STRING ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR STRING ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR ASSIGN VAR VAR VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR ASSIGN VAR VAR VAR STRING IF FUNC_CALL VAR VAR VAR VAR STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
def find_stars(h, w, matrix): max_size = 0 if matrix[h][w] == ".": return max_size size = 1 while True: for next_h in range(h, h + size + 1): if next_h >= height or matrix[next_h][w] != "*": return max_size for next_h in range(h, h - size - 1, -1): if next_h < 0 or matrix[next_h][w] != "*": return max_size for next_w in range(w, w + size + 1): if next_w >= width or matrix[h][next_w] != "*": return max_size for next_w in range(w, w - size - 1, -1): if next_w < 0 or matrix[h][next_w] != "*": return max_size max_size = size size += 1 height, width = list(map(int, input().split())) matrix = [] for h in range(height): row = input() matrix.append(row) result_matrix = [(["."] * width) for h in range(height)] result_stars = [] for h in range(height): for w in range(width): found_max_size = find_stars(h, w, matrix) if found_max_size == 0: continue for next_h in range(h, h + found_max_size + 1): result_matrix[next_h][w] = "*" for next_h in range(h, h - found_max_size - 1, -1): result_matrix[next_h][w] = "*" for next_w in range(w, w + found_max_size + 1): result_matrix[h][next_w] = "*" for next_w in range(w, w - found_max_size - 1, -1): result_matrix[h][next_w] = "*" result_stars.append(str(h + 1) + " " + str(w + 1) + " " + str(found_max_size)) is_equal = True for h in range(height): for w in range(width): if matrix[h][w] != result_matrix[h][w]: is_equal = False if is_equal: print(len(result_stars)) for star in result_stars: print(star) else: print(-1)
FUNC_DEF ASSIGN VAR NUMBER IF VAR VAR VAR STRING RETURN VAR ASSIGN VAR NUMBER WHILE NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR STRING RETURN VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER VAR VAR VAR STRING RETURN VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR STRING RETURN VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER VAR VAR VAR STRING RETURN VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR STRING FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
def valid(i, j): if (i >= 0 and i < n) and (j >= 0 and j < m): return True return False x = [int(x) for x in input().split()] n = x[0] m = x[1] a = [[(-1) for i in range(m)] for j in range(n)] k = [] s = [] for i in range(n): t = [x for x in input()] k.append(t) for l in range(n): for o in range(m): if k[l][o] == "*": a[l][o] = 0 for i in range(n): for j in range(m): count1 = 0 count2 = 0 count3 = 0 count4 = 0 if k[i][j] == "*": g = i while 1: if g < n - 1: if k[g + 1][j] == "*": count1 += 1 g += 1 else: break else: break g = j while 1: if g < m - 1: if k[i][g + 1] == "*": count2 += 1 g += 1 else: break else: break g = i while 1: if g > 0: if k[g - 1][j] == "*": count3 += 1 g -= 1 else: break else: break g = j while 1: if g > 0: if k[i][g - 1] == "*": count4 += 1 g -= 1 else: break else: break if min(count1, count2, count3, count4) > 0: l = min(count1, count2, count3, count4) o = [i + 1, j + 1, l] s.append(o) for p in range(l + 1): if valid(i + p, j): a[i + p][j] = -1 if valid(i - p, j): a[i - p][j] = -1 if valid(i, j + p): a[i][j + p] = -1 if valid(i, j - p): a[i][j - p] = -1 f = 0 for i in range(n): for j in range(m): if a[i][j] != -1: print(-1) f = 1 break if f == 1: break if f == 0: print(len(s)) for i in s: for j in i: print(j, end=" ") print()
FUNC_DEF IF VAR NUMBER VAR VAR VAR NUMBER VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR STRING ASSIGN VAR VAR WHILE NUMBER IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE NUMBER IF VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE NUMBER IF VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER STRING VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
n, m = input().strip().split(" ") n = int(n) m = int(m) grid = [] for i in range(n): grid.append(input()) mask = [([0] * m) for _ in range(n)] stars = dict() for i in range(n): for j in range(m): if grid[i][j] == ".": mask[i][j] = 1 else: stars[i, j] = 1 def get_largest_star(i, j): for x in range(1, min(i, n - i - 1, j, m - j - 1) + 1): if ( grid[i + x][j] != "*" or grid[i - x][j] != "*" or grid[i][j - x] != "*" or grid[i][j + x] != "*" ): return x - 1 return min(i, n - i - 1, j, m - j - 1) def fill_map(i, j, x): global mask mask[i][j] = 1 for y in range(1, x + 1): mask[i + y][j] = mask[i - y][j] = mask[i][j + y] = mask[i][j - y] = 1 num_stars = 0 my_stars = [] for star in stars: x = get_largest_star(star[0], star[1]) if x > 0: num_stars += 1 my_stars.append([star[0], star[1], x]) fill_map(star[0], star[1], x) possible = True for i in range(n): for j in range(m): if mask[i][j] == 0: possible = False break if not possible: print(-1) else: print(num_stars) for star in my_stars: print(str(star[0] + 1) + " " + str(star[1] + 1) + " " + str(star[2]))
ASSIGN VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING RETURN BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER STRING FUNC_CALL VAR VAR NUMBER
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $0$ are not allowed). Let's consider empty cells are denoted by '.', then the following figures are stars: [Image] The leftmost figure is a star of size $1$, the middle figure is a star of size $2$ and the rightmost figure is a star of size $3$. You are given a rectangular grid of size $n \times m$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $1$ to $n$, columns are numbered from $1$ to $m$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $n \cdot m$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes. In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $n \cdot m$ stars. -----Input----- The first line of the input contains two integers $n$ and $m$ ($3 \le n, m \le 100$) β€” the sizes of the given grid. The next $n$ lines contains $m$ characters each, the $i$-th line describes the $i$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only. -----Output----- If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $k$ ($0 \le k \le n \cdot m$) β€” the number of stars needed to draw the given grid. The next $k$ lines should contain three integers each β€” $x_j$, $y_j$ and $s_j$, where $x_j$ is the row index of the central star character, $y_j$ is the column index of the central star character and $s_j$ is the size of the star. Each star should be completely inside the grid. -----Examples----- Input 6 8 ....*... ...**... ..*****. ...**... ....*... ........ Output 3 3 4 1 3 5 2 3 5 1 Input 5 5 .*... ****. .**** ..**. ..... Output 3 2 2 1 3 3 1 3 4 1 Input 5 5 .*... ***.. .*... .*... ..... Output -1 Input 3 3 *.* .*. *.* Output -1 -----Note----- In the first example the output 2 3 4 1 3 5 2 is also correct.
import sys n, m = map(int, input().split()) s = [[*input()] for i in range(n)] f = [[(0) for i in range(m)] for i in range(n)] ans = [] for i in range(n): for j in range(m): if s[i][j] == ".": f[i][j] = 1 continue for k in range(1, min(n, m) + 1): if ( i + k < n and j + k < m and i - k >= 0 and j - k >= 0 and s[i + k][j] == "*" and s[i][j - k] == "*" and s[i - k][j] == "*" and s[i][j + k] == "*" ): f[i][j] = 1 f[i][j + k] = 1 f[i][j - k] = 1 f[i + k][j] = 1 f[i - k][j] = 1 else: if k > 1: ans.append((i + 1, j + 1, k - 1)) break for i in range(n): for j in range(m): if f[i][j] == 0: print(-1) sys.exit() print(len(ans)) for i in ans: print(i[0], i[1], i[2])
IMPORT ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING VAR BIN_OP VAR VAR VAR STRING VAR VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression. -----Input----- The first line contains expression s (1 ≀ |s| ≀ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs + and * . The number of signs * doesn't exceed 15. -----Output----- In the first line print the maximum possible value of an expression. -----Examples----- Input 3+5*7+8*4 Output 303 Input 2+3*5 Output 25 Input 3*4*5 Output 60 -----Note----- Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303. Note to the second sample test. (2 + 3) * 5 = 25. Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
str = input() n, result = len(str), eval(str) for i in range(-1, n): if i == -1 or str[i] == "*": for j in range(i + 1, n + 1): if j == n or str[j] == "*": result = max( result, eval(str[: i + 1] + "(" + str[i + 1 : j] + ")" + str[j:]) ) print(result)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression. -----Input----- The first line contains expression s (1 ≀ |s| ≀ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs + and * . The number of signs * doesn't exceed 15. -----Output----- In the first line print the maximum possible value of an expression. -----Examples----- Input 3+5*7+8*4 Output 303 Input 2+3*5 Output 25 Input 3*4*5 Output 60 -----Note----- Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303. Note to the second sample test. (2 + 3) * 5 = 25. Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
expr = input() muls = [] expr = "1*" + expr + "*1" for i in range(len(expr)): if expr[i] == "*": muls.append(i) ans = eval(expr) mc = len(muls) for i in range(mc - 1): for j in range(i + 1, mc): t = eval( expr[: muls[i] + 1] + "(" + expr[muls[i] + 1 : muls[j]] + ")" + expr[muls[j] :] ) if t > ans: ans = t print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR VAR NUMBER STRING VAR BIN_OP VAR VAR NUMBER VAR VAR STRING VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression. -----Input----- The first line contains expression s (1 ≀ |s| ≀ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs + and * . The number of signs * doesn't exceed 15. -----Output----- In the first line print the maximum possible value of an expression. -----Examples----- Input 3+5*7+8*4 Output 303 Input 2+3*5 Output 25 Input 3*4*5 Output 60 -----Note----- Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303. Note to the second sample test. (2 + 3) * 5 = 25. Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
s = input() a = [0] for i in range(len(s)): if s[i] == "*": a.append(i + 1) a.append(len(s) + 1) maxRes = eval(s) for i in a: for j in a: if j > i: maxRes = max(maxRes, eval(s[:i] + "(" + s[i : j - 1] + ")" + s[j - 1 :])) print(maxRes)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR STRING VAR VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression. -----Input----- The first line contains expression s (1 ≀ |s| ≀ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs + and * . The number of signs * doesn't exceed 15. -----Output----- In the first line print the maximum possible value of an expression. -----Examples----- Input 3+5*7+8*4 Output 303 Input 2+3*5 Output 25 Input 3*4*5 Output 60 -----Note----- Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303. Note to the second sample test. (2 + 3) * 5 = 25. Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
s = input() ma = eval(s) for i in range(len(s)): if s[i] == "*": s1 = s[:i] s2 = s[i - len(s) + 1 :] s3 = "(" + s1 + ")*" + s2 ma = max(ma, eval(s3)) s3 = s1 + "*(" + s2 + ")" ma = max(ma, eval(s3)) for j in range(i): if s[j] == "*": s1 = s[:j] s3 = s[j + 1 : i - len(s)] s4 = s1 + "*(" + s3 + ")*" + s2 ma = max(ma, eval(s4)) print(ma)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP STRING VAR STRING VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR STRING VAR STRING VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression. -----Input----- The first line contains expression s (1 ≀ |s| ≀ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs + and * . The number of signs * doesn't exceed 15. -----Output----- In the first line print the maximum possible value of an expression. -----Examples----- Input 3+5*7+8*4 Output 303 Input 2+3*5 Output 25 Input 3*4*5 Output 60 -----Note----- Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303. Note to the second sample test. (2 + 3) * 5 = 25. Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
s = input() w = "1*" + s + "*1" n = len(w) res = eval(w) for i in range(n): if w[i] == "*": for j in range(i + 1, n): if w[j] == "*": temp = eval(w[: i + 1] + "(" + w[i + 1 : j] + ")" + w[j:]) res = max(res, temp) print(res)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression. -----Input----- The first line contains expression s (1 ≀ |s| ≀ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs + and * . The number of signs * doesn't exceed 15. -----Output----- In the first line print the maximum possible value of an expression. -----Examples----- Input 3+5*7+8*4 Output 303 Input 2+3*5 Output 25 Input 3*4*5 Output 60 -----Note----- Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303. Note to the second sample test. (2 + 3) * 5 = 25. Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
s = "1*" + input() + "*1" poses = [] for i in range(len(s)): if s[i] == "*": poses.append(i) ans = 0 for i in poses: for j in poses: if i < j: t = s[: i + 1] + "(" + s[i + 1 : j] + ")" + s[j:] ans = max(ans, eval(t)) print(ans)
ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression. -----Input----- The first line contains expression s (1 ≀ |s| ≀ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs + and * . The number of signs * doesn't exceed 15. -----Output----- In the first line print the maximum possible value of an expression. -----Examples----- Input 3+5*7+8*4 Output 303 Input 2+3*5 Output 25 Input 3*4*5 Output 60 -----Note----- Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303. Note to the second sample test. (2 + 3) * 5 = 25. Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
s = input() s = "1*" + s + "*1" lx = len(s) rep = eval(s) pos = [] for i in range(lx): if s[i] == "*": pos.append(i) sz = len(pos) for aa1 in range(sz): for aa2 in range(aa1 + 1, sz): a1 = pos[aa1] a2 = pos[aa2] ns = "" for i in range(lx): if i == a2: ns += ")" ns += s[i] if i == a1: ns += "(" rep = max(rep, eval(ns)) print(rep)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR STRING VAR VAR VAR IF VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression. -----Input----- The first line contains expression s (1 ≀ |s| ≀ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs + and * . The number of signs * doesn't exceed 15. -----Output----- In the first line print the maximum possible value of an expression. -----Examples----- Input 3+5*7+8*4 Output 303 Input 2+3*5 Output 25 Input 3*4*5 Output 60 -----Note----- Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303. Note to the second sample test. (2 + 3) * 5 = 25. Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
s = "1*" + input() + "*1" L = len(s) ans = eval(s) for i in range(L): if s[i] == "*": for j in range(i + 1, L): if s[j] == "*": ans = max(ans, eval(s[: i + 1] + "(" + s[i + 1 : j] + ")" + s[j:])) print(ans)
ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER VAR STRING VAR VAR EXPR FUNC_CALL VAR VAR
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression. -----Input----- The first line contains expression s (1 ≀ |s| ≀ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs + and * . The number of signs * doesn't exceed 15. -----Output----- In the first line print the maximum possible value of an expression. -----Examples----- Input 3+5*7+8*4 Output 303 Input 2+3*5 Output 25 Input 3*4*5 Output 60 -----Note----- Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303. Note to the second sample test. (2 + 3) * 5 = 25. Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
s = input() r = [0] t = s.find("*") while -1 != t: r += [t] t = s.find("*", t + 1) r += [len(s)] R = 0 for i in range(len(r)): for j in range(i + 1, len(r)): a = r[i] b = r[j] t = s[:a] if t: t += "*" a += 1 t += "(" + s[a:b] + ")" + s[b:] R = max(R, eval(t)) print(R)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR STRING WHILE NUMBER VAR VAR LIST VAR ASSIGN VAR FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR LIST FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR STRING VAR NUMBER VAR BIN_OP BIN_OP BIN_OP STRING VAR VAR VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression. -----Input----- The first line contains expression s (1 ≀ |s| ≀ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs + and * . The number of signs * doesn't exceed 15. -----Output----- In the first line print the maximum possible value of an expression. -----Examples----- Input 3+5*7+8*4 Output 303 Input 2+3*5 Output 25 Input 3*4*5 Output 60 -----Note----- Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303. Note to the second sample test. (2 + 3) * 5 = 25. Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
s = "1*" + input() + "*1" muls = [1] for i in range(3, len(s) - 2, 2): if s[i] == "*" and (s[i - 2] == "+" or s[i + 2] == "+"): muls.append(i) muls.append(len(s) - 2) m = eval(s) for i in range(len(muls)): for j in range(i + 1, len(muls)): a, b = muls[i], muls[j] new_s = s[: a + 1] + "(" + s[a + 1 : b] + ")" + s[b:] m = max(m, eval(new_s)) print(m)
ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR STRING ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR STRING VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER STRING VAR BIN_OP VAR NUMBER VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression. -----Input----- The first line contains expression s (1 ≀ |s| ≀ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs + and * . The number of signs * doesn't exceed 15. -----Output----- In the first line print the maximum possible value of an expression. -----Examples----- Input 3+5*7+8*4 Output 303 Input 2+3*5 Output 25 Input 3*4*5 Output 60 -----Note----- Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303. Note to the second sample test. (2 + 3) * 5 = 25. Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
s = input() n = len(s) p = [-1] + [i for i in range(n) if s[i] == "*"] + [n] m = len(p) ans = eval(s) for i in range(m): for j in range(i + 1, m): a, b = p[i] + 1, p[j] t = s[:a] + "(" + s[a:b] + ")" + s[b:] ans = max(ans, eval(t)) print(ans)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR VAR VAR STRING LIST VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR STRING VAR VAR VAR STRING VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR