gemma-3-27b-it· Google LMArena Human Preference 140K
Optimised it that all test case will passed only give answer remove comments
- User
Optimised it that all test case will passed only give answer remove comments
- Assistant
import sys def main(): sys.setrecursionlimit(1 << 25) input = sys.stdin.read data = input().split() idx = 0 N = int(data[idx]) idx += 1 K = int(data[idx]) idx += 1 A = [] for _ in range(N): A.append(int(data[idx])) idx += 1 Par = [] for _ in range(N): Par.append(int(data[idx])) idx += 1 tree = [[] for _ in range(N)] for i in range(N): if Par[i] != 0: tree[Par[i]-1].append(i) depth = [0] * N stack = [(0, -1)] while stack: node, parent = stack.pop() for child in tree[node]: if child != parent: depth[child] = depth[node] + 1 stack.append((child, node)) def dfs(node): current_list = [] for child in tree[node]: child_list = dfs(child) if len(child_list) > len(current_list): current_list, child_list = child_list, current_list current_list.extend(child_list) max_val = 0 for a, d, dp_val in current_list: if d >= depth[node] + K + 1 and a >= A[node]: max_val = max(max_val, dp_val) dp_val = 1 + max_val if max_val > 0 else 1 current_list.append((A[node], depth[node], dp_val)) return current_list all_lists = dfs(0) max_dp = 0 for a, d, dp_val in all_lists: max_dp = max(max_dp, dp_val) print(max_dp) if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.