Submission #55544837


Source Code Expand

#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
int MOD = 998244353;
const int N = 80;

int a[N];
ll memo[N+1][N+1];
ll n;
int barrier;
ll seed, diff;
// arithmetic sequences in (barrier, i] whose length is k
ll dp(int i, int k) {
    if (k == 2) {
        return 1;
    }
    if (i == barrier) {
        return 0;
    }
    if (memo[i][k] != -1) {
        return memo[i][k];
    }

    ll ans = dp(i-1, k); // skip
    if (a[i] == seed + (k-1)*diff) {
        ans = (ans + dp(i-1, k-1)) % MOD;
    }
    return memo[i][k] = ans;
}
int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<ll> ans(n+1, 0);
    ans[1] = n;
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            seed = a[i];
            diff = a[j] - a[i];
            barrier = j;
            memset(memo, -1, sizeof memo);
            for (int k = 2; k <= n; k++) {
                ans[k] = (ans[k] + dp(n-1, k)) % MOD;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << ans[i] << ' ';
    }
    cout << '\n';
    return 0;
}

Submission Info

Submission Time
Task E - Count Arithmetic Subsequences
User Shisuko
Language C++ 20 (gcc 12.2)
Score 475
Code Size 1203 Byte
Status AC
Exec Time 74 ms
Memory 3752 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 1 ms 3604 KiB
00_sample_02.txt AC 1 ms 3604 KiB
00_sample_03.txt AC 1 ms 3564 KiB
01_random_01.txt AC 4 ms 3556 KiB
01_random_02.txt AC 49 ms 3488 KiB
01_random_03.txt AC 47 ms 3612 KiB
01_random_04.txt AC 50 ms 3752 KiB
01_random_05.txt AC 1 ms 3484 KiB
01_random_06.txt AC 48 ms 3564 KiB
01_random_07.txt AC 1 ms 3592 KiB
01_random_08.txt AC 49 ms 3616 KiB
01_random_09.txt AC 1 ms 3500 KiB
01_random_10.txt AC 49 ms 3540 KiB
01_random_11.txt AC 23 ms 3748 KiB
01_random_12.txt AC 49 ms 3544 KiB
01_random_13.txt AC 4 ms 3612 KiB
01_random_14.txt AC 49 ms 3568 KiB
01_random_15.txt AC 31 ms 3560 KiB
01_random_16.txt AC 49 ms 3680 KiB
01_random_17.txt AC 33 ms 3748 KiB
01_random_18.txt AC 48 ms 3604 KiB
01_random_19.txt AC 12 ms 3612 KiB
01_random_20.txt AC 49 ms 3560 KiB
02_handmade_01.txt AC 17 ms 3560 KiB
02_handmade_02.txt AC 74 ms 3488 KiB
02_handmade_03.txt AC 49 ms 3556 KiB
02_handmade_04.txt AC 49 ms 3556 KiB
02_handmade_05.txt AC 49 ms 3560 KiB
02_handmade_06.txt AC 49 ms 3604 KiB