Submission #55562909


Source Code Expand

import sys,math,random
from heapq import heappush,heappop
from bisect import bisect_right,bisect_left
from collections import Counter,deque,defaultdict

# functions #
MOD = 998244353
RANDOM = random.randrange(2**62)
def gcd(a,b):
    if a%b==0:
        return b
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a//gcd(a,b)*b
def w(x):
    return x ^ RANDOM
##

#String hashing : sh, fenwick sortedlist : fsortl, sieve : sieve, SparseTable : SparseTable
#bucket sorted list : bsortl, segment tree(lazy propogation) : SegmentTree, bootstrap : bootstrap
#binary indexed tree : BIT, segment tree(point updates) : SegmentPoint, Convex Hull : hull
#Combinatorics : pnc
#Template : https://github.com/OmAmar106/Template-for-Competetive-Programming

def solve():
    n = int(sys.stdin.readline().strip())
    L = list(map(int, sys.stdin.readline().split()))
    ans = [0 for i in range(n)]
    # dp[i][nofe][diff]++
    dp = [[{} for i in range(n+1)] for j in range(n)]
    for i in range(n):
        dp[i][1][0] = 1
        ans[0] += 1
        for j in range(i-1,-1,-1):
            f = L[i]-L[j]
            if f in dp[i][2]:
                dp[i][2][f] += 1
            else:
                dp[i][2][f] = 1
            ans[1] += 1
            for k in range(2,n):
                if f in dp[j][k]:
                    if f in dp[i][k+1]:
                        dp[i][k+1][f] += dp[j][k][f]
                    else:
                        dp[i][k+1][f] = dp[j][k][f]
                    ans[k] += dp[j][k][f]
                    ans[k] %= MOD
                    dp[i][k+1][f] %= MOD
    for i in range(len(ans)):
        ans[i] %= MOD
    print(*ans)
    #L1 = list(map(int, sys.stdin.readline().split()))
    #st = sys.stdin.readline().strip()
solve()

Submission Info

Submission Time
Task E - Count Arithmetic Subsequences
User OmAmar106
Language Python (Cython 0.29.34)
Score 475
Code Size 1818 Byte
Status AC
Exec Time 48 ms
Memory 11212 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 3
AC × 29
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 12 ms 9876 KiB
00_sample_02.txt AC 13 ms 9896 KiB
00_sample_03.txt AC 13 ms 9804 KiB
01_random_01.txt AC 14 ms 9952 KiB
01_random_02.txt AC 23 ms 10328 KiB
01_random_03.txt AC 22 ms 10364 KiB
01_random_04.txt AC 22 ms 10288 KiB
01_random_05.txt AC 12 ms 9948 KiB
01_random_06.txt AC 21 ms 10440 KiB
01_random_07.txt AC 12 ms 9796 KiB
01_random_08.txt AC 22 ms 10412 KiB
01_random_09.txt AC 12 ms 9732 KiB
01_random_10.txt AC 22 ms 10476 KiB
01_random_11.txt AC 18 ms 10236 KiB
01_random_12.txt AC 22 ms 10572 KiB
01_random_13.txt AC 15 ms 9964 KiB
01_random_14.txt AC 22 ms 10568 KiB
01_random_15.txt AC 19 ms 10244 KiB
01_random_16.txt AC 22 ms 10568 KiB
01_random_17.txt AC 20 ms 10328 KiB
01_random_18.txt AC 21 ms 10376 KiB
01_random_19.txt AC 16 ms 10204 KiB
01_random_20.txt AC 22 ms 10480 KiB
02_handmade_01.txt AC 25 ms 10300 KiB
02_handmade_02.txt AC 48 ms 10892 KiB
02_handmade_03.txt AC 25 ms 11056 KiB
02_handmade_04.txt AC 25 ms 11212 KiB
02_handmade_05.txt AC 23 ms 10692 KiB
02_handmade_06.txt AC 23 ms 10736 KiB