Please read the new rule regarding the restriction on the use of AI tools. ×

RawBear's blog

By RawBear, history, 2 years ago, In English

Hi, I've got problem with solving linked below problem https://codeforces.me/problemset/problem/1708/A

In summary, my code is creating array contains positive numbers, as long as the numbers in the array are in ascending order there is possibility that I can return array contains first number and the rest would be zeros such like A[n,0,0]. I can modify array by performing operation (any number of times): A[i] = A[i] — A[i -1], where i is index, and (2 <= i <=len(A)). I need to write Yes if my final modified array A[1:] would be fill with only zeros, if not print No. My code is giving good output for examples but don't pass tests. I don't know where is the bug.

I paste my code written in python below.

n = int(input())
for i in range(n):
    l = int(input())
    array = list(map(int, input().split()))
    while array == sorted(array):
            for i in range(l - 1,0, -1):
                array[i] = array[i] - array[i - 1]
    result = all(element == 0 for element in array[1:])
    if result:
        print('YES')
    else:
        print('NO')

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it