Submission #6835387


Source Code Expand

Copy
#include <iostream>

using namespace std;

int bexp(int a, int x, int p) {
    if (x == 0) {
        return 1;
    }
    if (x % 2 == 1) {
        return a * bexp(a, x - 1, p) % p;
    }
    int t = bexp(a, x / 2, p);
    return t * t % p;
}

int inv(int a, int p) {
    return bexp(a, p - 2, p);
}

int main() {
    int p;
    cin >> p;
    int a[p];
    for (int i = 0; i < p; i++) {
        cin >> a[i];
    }

    int c[p][p];
    for (int i = 0; i < p; i++) {
        c[i][0] = c[i][i] = 1;
        for (int j = 1; j < i; j++) {
            c[i][j] = (c[i-1][j-1] + c[i-1][j]) % p;
        }
    }

    int e[p][p];
    for (int i = 0; i < p; i++) {
        for (int j = 0; j < p; j++) {
            e[i][j] = j == 0 ? 1 : e[i][j-1] * i % p;
        }
    }

    int b[p];
    for (int i = p - 1; i >= 0; i--) {
        int x = 0, y = 0;
        int neg = 1;
        for (int j = i; j >= 0; j--) {
            y = ((y + a[j] * c[i][j] * neg) % p + p) % p;
            x = ((x + e[j][i] * c[i][j] * neg) % p + p) % p;
            neg = -neg;
        }
        b[i] = x == 0 ? 0 : y * inv(x, p) % p;

        for (int j = 0; j < p; j++) {
            a[j] = ((a[j] - b[i] * e[j][i]) % p + p) % p;
        }
    }

    for (int i = 0; i < p; i++) {
        cout << b[i] << (i == p - 1 ? '\n' : ' ');
    }

    return 0;
}

Submission Info

Submission Time
Task F - Polynomial Construction
User fdironia
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1389 Byte
Status AC
Exec Time 265 ms
Memory 70400 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 43
Set Name Test Cases
Sample a01, a02, a03
All a01, a02, a03, b04, b05, b06, b07, b08, b09, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24, b25, b26, b27, b28, b29, b30, b31, b32, b33, b34, b35, b36, b37, b38, b39, b40, b41, b42, b43
Case Name Status Exec Time Memory
a01 AC 1 ms 256 KB
a02 AC 1 ms 256 KB
a03 AC 1 ms 256 KB
b04 AC 1 ms 256 KB
b05 AC 1 ms 256 KB
b06 AC 1 ms 256 KB
b07 AC 259 ms 69248 KB
b08 AC 261 ms 69888 KB
b09 AC 260 ms 69504 KB
b10 AC 261 ms 69632 KB
b11 AC 263 ms 69632 KB
b12 AC 263 ms 70016 KB
b13 AC 265 ms 70272 KB
b14 AC 262 ms 70272 KB
b15 AC 262 ms 69504 KB
b16 AC 262 ms 70272 KB
b17 AC 262 ms 69632 KB
b18 AC 262 ms 70144 KB
b19 AC 262 ms 70016 KB
b20 AC 262 ms 69504 KB
b21 AC 264 ms 70400 KB
b22 AC 264 ms 69760 KB
b23 AC 263 ms 70272 KB
b24 AC 262 ms 70400 KB
b25 AC 262 ms 69888 KB
b26 AC 263 ms 69632 KB
b27 AC 262 ms 70400 KB
b28 AC 264 ms 70272 KB
b29 AC 263 ms 70400 KB
b30 AC 263 ms 69504 KB
b31 AC 262 ms 69888 KB
b32 AC 262 ms 69760 KB
b33 AC 1 ms 256 KB
b34 AC 1 ms 256 KB
b35 AC 257 ms 68864 KB
b36 AC 258 ms 68992 KB
b37 AC 76 ms 21632 KB
b38 AC 144 ms 39680 KB
b39 AC 1 ms 256 KB
b40 AC 112 ms 31232 KB
b41 AC 3 ms 640 KB
b42 AC 37 ms 9856 KB
b43 AC 163 ms 44160 KB