Submission #6830762


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;
const int maxn=3010;
int mod;
void plusle(int &a,int b){
    a+=b;if(a>=mod)a-=mod; return;
}
void minun(int &a,int b){
    a-=b; if(a<0)a+=mod; return;
}
int add(int a,int b) {
  a+=b;
  return a>=mod?a-mod:a;
}
int sub(int a,int b) {
  a-=b;
  return a<0?a+mod:a;
}
int mul(int a,int b) {
  return (int)((long long)a*b%mod);
}
int power(int a,int b) {
  int res=1;
  while (b>0) {
    if (b&1) {
      res=mul(res,a);
    }
    a=mul(a,a);
    b>>=1;
  }
  return res;
}
int inv(int x){
    return power(x,mod-2);
}
vector<int> mul(const vector<int> &p,int j){
    ///c[0]+(c[1]*x)+(c[2]*(x^2)+...)c[n-1]*(x^(n-1))
    ///(x-j)
    int n=(int)p.size();
    vector<int> s(n+1,0);
    for(int i=0;i<n;i++){
        plusle(s[i+1],p[i]);
    }
    for(int i=0;i<n;i++){
        plusle(s[i],mul(p[i],j));
    }
    return s;
}
vector<int> d( vector<int> p,int j){
    ///c[0]+c[1]*x+...+c[n-1]*(x^(n-1))
    ///x-j
    int n=(int)p.size();
    vector<int> s(n-1,0);
    for(int i=n-1;i>0;i--){
        plusle(p[i-1],mul(j,p[i]));
        s[i-1]=p[i];
    }
    return s;
}
int get(const vector<int> &g,int x){
    int res=0;
    int now=1;
    for(int i=0;i<(int)g.size();i++){
        plusle(res,mul(g[i],now));
        now=mul(now,x);
    }
    return res;
}
int a[maxn];

int main(){
    int p;
    scanf("%d",&p);
    mod=p;
    for(int i=0;i<p;i++){
        scanf("%d",&a[i]);
    }
    vector<int> t={0,1};
    for(int i=1;i<p;i++){
        t=mul(t,i);
    }
    vector<int> aa(p,0);
    for(int i=0;i<p;i++){
        if(a[i]==0)continue;
        vector<int> s=d(t,i);
        int cur=get(s,i);
        cur=inv(cur);
        for(int i=0;i<(int)s.size();i++){
            plusle(aa[i],mul(s[i],cur));
        }
    }
    for(int i:aa){
        printf("%d ",i);
    }
}
/*
    Good Luck
        -Lucina
*/

Submission Info

Submission Time
Task F - Polynomial Construction
User Lucina
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1953 Byte
Status AC
Exec Time 579 ms
Memory 384 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:74:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&p);
                   ^
./Main.cpp:77:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a[i]);
                          ^

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 85 ms 256 KB
b08 AC 579 ms 256 KB
b09 AC 579 ms 256 KB
b10 AC 579 ms 256 KB
b11 AC 85 ms 256 KB
b12 AC 85 ms 256 KB
b13 AC 332 ms 256 KB
b14 AC 332 ms 256 KB
b15 AC 156 ms 256 KB
b16 AC 511 ms 256 KB
b17 AC 332 ms 256 KB
b18 AC 332 ms 256 KB
b19 AC 326 ms 256 KB
b20 AC 426 ms 256 KB
b21 AC 529 ms 256 KB
b22 AC 553 ms 256 KB
b23 AC 576 ms 256 KB
b24 AC 577 ms 256 KB
b25 AC 579 ms 256 KB
b26 AC 340 ms 256 KB
b27 AC 236 ms 256 KB
b28 AC 136 ms 256 KB
b29 AC 113 ms 256 KB
b30 AC 89 ms 256 KB
b31 AC 88 ms 256 KB
b32 AC 85 ms 256 KB
b33 AC 1 ms 256 KB
b34 AC 1 ms 256 KB
b35 AC 288 ms 256 KB
b36 AC 446 ms 384 KB
b37 AC 143 ms 256 KB
b38 AC 68 ms 256 KB
b39 AC 1 ms 256 KB
b40 AC 110 ms 256 KB
b41 AC 4 ms 256 KB
b42 AC 33 ms 256 KB
b43 AC 72 ms 256 KB