Submission #1393848


Source Code Expand

# include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef unsigned long long ull;

const int N = int(5e5) + 5;
const int inf = (int)1e9 + 7;

int binpow(int n, int k){
  if(k == 0){
    return 1 % inf;
  }
  int z = binpow(n, k / 2);
  z = z * 1ll * z % inf;
  if(k & 1){
    z = z * 1ll * n % inf;
  }
  return z;
}

int n;
int a[N], u[N], p1, p2;
int f[N], rf[N];

int cnk(int n, int k){
  if(n < k){
    return 0;
  }
  return (f[n] * 1ll * rf[k] % inf) * 1ll * rf[n - k] % inf;
}

int main(){
  scanf("%d", &n);
  f[0] = 1;
  for(int i = 1; i <= n * 2 + 3; ++i){
    f[i] = f[i - 1] * 1ll * i % inf;
  }
  rf[n * 2 + 3] = binpow(f[n * 2 + 3], inf - 2);
  for(int i = n * 2 + 2; i >= 0; --i){
    rf[i] = rf[i + 1] * 1ll * (i + 1) % inf;
  }
  for(int i = 1; i <= n + 1; ++i){
    scanf("%d", a + i);
    if(u[a[i]]){
      p2 = i;
      p1 = u[a[i]];
    }
    u[a[i]] = i;
  }
  printf("%d\n", n);
  // sum cnk(a, x) * cnk(b, len - x)
  for(int len = 2; len <= n + 1; ++len){
    int ans = cnk(n + 1, len);
    int tot = p1 - 1 + (n + 1) - p2;
    ans -= cnk(tot, len - 1);
    if(ans < 0){
      ans += inf;
    }
    printf("%d\n", ans);
  }
  return 0;
}

Submission Info

Submission Time
Task D - 11
User aaaaab
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1305 Byte
Status AC
Exec Time 24 ms
Memory 6272 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:37:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
                  ^
./Main.cpp:47:23: 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 × 10
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All 1.txt, mx.txt, rnd_0.txt, rnd_1.txt, rnd_2.txt, rnd_3.txt, rnd_4.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
1.txt AC 24 ms 6272 KB
mx.txt AC 24 ms 6272 KB
rnd_0.txt AC 20 ms 5888 KB
rnd_1.txt AC 17 ms 5632 KB
rnd_2.txt AC 6 ms 4736 KB
rnd_3.txt AC 6 ms 4736 KB
rnd_4.txt AC 8 ms 4992 KB
sample1.txt AC 2 ms 4352 KB
sample2.txt AC 2 ms 4352 KB
sample3.txt AC 2 ms 4352 KB