Submission #1399516


Source Code Expand

#include <iostream>
#include <sstream>
#include <fstream>

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>

#include <algorithm>
#include <numeric>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
// #include <unordered_map>
#include <set>
#include <utility>
#include <bitset>
#include <limits>
#include <climits>
using namespace std;

#ifdef DEBUG
#define NDEBUG
#include "cout11.h"
#endif
#undef NDEBUG
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

const ll M=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % M; }
ll SUB(ll x, ll y) { return (x-y+M) % M; }
ll MUL(ll x, ll y) { return x*y % M; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { return MUL(x, POW(y, M-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }

#define INTSPACE 11
char _buf[INTSPACE*1000000 + 3];  // ここ要確認

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}
int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}


void prepare_comb(vector<ll>& ar, int n) {
    ar.resize(n+1);
    ar[0] = 1LL;
    for (ll i=1; i<=n; i++) {
        ar[i] = DIV(MUL(ar[i-1], n-i+1), i);
    }
    // cout << "prepare_comb(" << n << ") -> " << ar << endl;
}

void solve(vector<int>& a) {
    int n = a.size() - 1;
    int dub = -1;
    int first, second;
    vector<int> loc(n, -1);
    rep(i, n+1) {
        int a_i = a[i]-1;
        if (loc[a_i] != -1) {
            dub = a_i;
            first = loc[a_i];
            second = i;
        } else {
            loc[a_i] = i;
        }
    }
    int w1 = first-0, w2 = second-(first+1), w3 = (n+1)-(second+1);

    vector<ll> C;
    prepare_comb(C, w1+w3);

#ifdef DEBUG
    printf("N=%d\n", n);
    cout << a << endl;
    cout << loc << endl;
    printf("doubled: %d (at %d and %d)\n", 1+dub, first, second);
    printf("|%d|%d|%d|\n", w1, w2, w3);
#endif

    ll v = 1;
    for (int k=1; k<=n+1; ++k) {
        v = DIV(MUL(v, (n+1)-k+1), k);
        ll x = v;
        if (k-1 <= w1+w3) {
            // printf(" // k=%d; %lld - (%lld=wC%d)\n", k, x, C[k-1], k-1);
            x = SUB(x, C[k-1]);
        }
        if (k == 1) {
            printf("%d\n", n);
            continue;
        }
        printf("%lld\n", x);
    }
}

int main() {
    int N = loadint();
    vector<int> a(N+1);
    loadvec(a, N+1);

    solve(a);
}

Submission Info

Submission Time
Task D - 11
User naoya_t
Language C++14 (GCC 5.4.1)
Score 600
Code Size 4016 Byte
Status AC
Exec Time 46 ms
Memory 3328 KB

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 46 ms 3328 KB
mx.txt AC 30 ms 2560 KB
rnd_0.txt AC 33 ms 2560 KB
rnd_1.txt AC 25 ms 2048 KB
rnd_2.txt AC 10 ms 768 KB
rnd_3.txt AC 9 ms 768 KB
rnd_4.txt AC 11 ms 1024 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 1 ms 256 KB