Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ Homework
- 1) Check if there is a quadruple such that:
- (i, j, k, z): i < j < k < z and a[i] + a[j] = a[k] + a[z]
- N <= 2000
- 2) Check if there is a quadruple such that:
- (i, j, k, z): i < j < k < z and a[i] + a[k] = a[j] + a[z]
- N <= 2000
- 3) Check if there is a quadruple such that:
- (i, j, k, z): i < j < k < z and a[i] * a[k] = a[j] * a[z], https://community.topcoder.com/stat?c=problem_statement&pm=13951
- N <= 2000
- 4) Find the maximum side of a cross of 1's in a matrix, N <= 2000. Think about a harder version: https://codeforces.com/problemset/problem/677/E; Don't care about the big number part.
- """
- #####
- # 1 #
- #####
- a = [int(i) for i in input().split(' ')]
- def exists(a):
- n = len(a)
- d = {}
- for i in range(n):
- for j in range(i + 1, n):
- s = a[i] + a[j]
- if s not in d:
- d[s] = j
- for z in range(n - 1, -1, -1):
- for k in range(z - 1, -1, -1):
- s = a[z] + a[k]
- if s in d and d[s] < k:
- return True
- return False
- print(exists(a))
- #####
- # 2 #
- #####
- a = [int(i) for i in input().split(' ')]
- def exists(a):
- n = len(a)
- d = {}
- for i in range(n):
- for j in range(i + 1, n):
- s = a[i] - a[j]
- if s not in d:
- d[s] = j
- for z in range(n - 1, -1, -1):
- for k in range(z - 1, -1, -1):
- s = a[z] - a[k]
- if s in d and d[s] < k:
- return True
- return False
- print(exists(a))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement