AtCoder Beginner Contest 066

Submission #1398652

Source codeソースコード

/* template.cpp(shinobu_menkoi) {{{ */
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (lint i = (a); i < (lint)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (lint i = (a); i >= (lint)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
#define TEMP_T template <class T>
#define TEMP_TU template <class T, class U>

TEMP_T using vec = vector<T>;
TEMP_T using heap = priority_queue<T>;
TEMP_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using lint = long long;
using ulint = unsigned long long;
using ld = long double;
using vi = vec<int>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<int, int>;
using vs = vec<string>;

TEMP_TU ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.fi << " " << p.se; }
TEMP_TU istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.fi >> p.se; }

const int INF{1001001001};
const lint LINF{1001001001001001001ll};
const lint MOD{(lint)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

inline bool inside(int y, int x, int h, int w) { return y >= 0 && x >= 0 && y < h && x < w; }
TEMP_T inline bool chmin(T &a, const T &b) { if (a > b) a = b; return a > b; }
TEMP_T inline bool chmax(T &a, const T &b) { if (a < b) a = b; return a < b; }
TEMP_T inline void print(const T &x) { cout << x << '\n'; }
TEMP_T inline void print(const vec<T> &v, string d = "\n") { rep(i, v.size()) cout << v[i] << (i == (lint)v.size() - 1 ? "\n" : d); }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = string> vec<T> split(const string &s, char d = ',') {
  vec<T> v; stringstream ss(s); for (string b; getline(ss, b, d); ) {
    stringstream conv(b); T t; conv >> t; v.eb(t); } return v;
}
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;
// clang-format on
/* }}} */

lint fact[100010], ifact[100010];

lint pow(lint a, lint k) {
  if (k == 0) return 1;
  lint res = pow(a, k / 2);
  res = res * res % MOD;
  if (k & 1) res = res * a % MOD;
  return res;
}

lint inv(lint a) {
  return pow(a, MOD - 2);
}

lint C(lint n, lint r) {
  if (n < 0 || r < 0 || r > n) return 0;
  if (r > n / 2) r = n - r;
  return fact[n] * ifact[r] % MOD * ifact[n - r] % MOD;
}

signed main() {
  lint n = in();
  int N = n + 1;

  fact[0] = ifact[0] = 1;
  rep(i, 1, 100010) {
    fact[i] = (fact[i - 1] * i) % MOD;
    ifact[i] = inv(fact[i]);
  }

  int d = -1;
  int used[100010];
  fill(all(used), -1);

  rep(i, N) {
    int a;
    cin >> a;
    if (used[a] != -1) {
      d = i - used[a];
    }
    used[a] = i;
  }

  rep(i, N) { print((C(N, i + 1) - C(N - d - 1, i) + MOD) % MOD); }
}

Submission

Task問題 D - 11
User nameユーザ名 佐々木千枝
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 600
Source lengthソースコード長 3511 Byte
File nameファイル名
Exec time実行時間 46 ms
Memory usageメモリ使用量 3200 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample1.txt,sample2.txt,sample3.txt
All 600 / 600 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

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
1.txt AC 46 ms 3200 KB
mx.txt AC 45 ms 3200 KB
rnd_0.txt AC 42 ms 3072 KB
rnd_1.txt AC 40 ms 2944 KB
rnd_2.txt AC 32 ms 2432 KB
rnd_3.txt AC 31 ms 2432 KB
rnd_4.txt AC 33 ms 2560 KB
sample1.txt AC 28 ms 2176 KB
sample2.txt AC 28 ms 2176 KB
sample3.txt AC 28 ms 2176 KB