AtCoder Regular Contest 023

Submission #1066276

Source codeソースコード

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
template<class T> using vv=vector<vector< T > >;

int mod = 1e9 + 7;

ll po(ll k, ll x) {
  if (x == 0) {
    return 1;
  }
  if (x == 1) {
    return k % mod;
  }
  ll y = po(k, x/2);
  y = y * y % mod;
  if (x % 2 == 1) {
    y = y * k % mod;
  }
  return y;
}

ll combination(ll n, ll k) {
  k = min(k, n-k);
  if (k == 0) {
    return 1;
  }
  ll ret = 1;
  FOR (i, n-k+1, n+1) {
    ret = ret * i % mod;
  }
  ll denomi = 1; // denominator
  FOR (i, 1, k+1) {
    denomi = denomi * i % mod;
  }
  ret = ret * po(denomi, mod-2) % mod;
  return ret;
}

int main() {
  int n;
  scanf("%d", &n);
  vi a(n);
  rep (i, n) {
    scanf("%d", &a[i]);
  }
  vector<pii> calc_comb;
  int index = 0;
  FOR (i, 1, n) {
    if (a[i] != -1) {
      calc_comb.push_back((pii){(ll)a[i] - a[index] + i - index - 1, i - index - 1});
      index = i;
    }
  }
  int sz = calc_comb.size();
  ll ans = 1;
  rep (i, sz) {
    ans = ans * combination(calc_comb[i].first, calc_comb[i].second) % mod;
  }
  printf("%lld\n", ans);

  return 0;
}

Submission

Task問題 C - タコヤ木
User nameユーザ名 cyglef
Created time投稿日時
Language言語 C++11 (GCC 4.8.1)
Status状態 AC
Score得点 100
Source lengthソースコード長 1930 Byte
File nameファイル名
Exec time実行時間 20 ms
Memory usageメモリ使用量 928 KB

Compiler messageコンパイルメッセージ

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

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt,sample_03.txt
Subtask1 50 / 50 sample_01.txt,sample_02.txt,subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt
Subtask2 30 / 30 sample_01.txt,sample_02.txt,subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask2_01.txt,subtask2_02.txt,subtask2_03.txt,subtask2_04.txt,subtask2_05.txt,subtask2_06.txt,subtask2_07.txt,subtask2_08.txt,subtask2_09.txt,subtask2_10.txt,subtask2_11.txt,subtask2_12.txt
Subtask3 20 / 20 subtask1_01.txt,subtask1_02.txt,subtask1_03.txt,subtask1_04.txt,subtask1_05.txt,subtask1_06.txt,subtask1_07.txt,subtask1_08.txt,subtask1_09.txt,subtask1_10.txt,subtask1_11.txt,subtask1_12.txt,subtask2_01.txt,subtask2_02.txt,subtask2_03.txt,subtask2_04.txt,subtask2_05.txt,subtask2_06.txt,subtask2_07.txt,subtask2_08.txt,subtask2_09.txt,subtask2_10.txt,subtask2_11.txt,subtask2_12.txt,subtask3_01.txt,subtask3_02.txt,subtask3_03.txt,subtask3_04.txt,subtask3_05.txt,subtask3_06.txt,subtask3_07.txt,subtask3_08.txt,subtask3_09.txt,subtask3_10.txt,subtask3_11.txt,subtask3_12.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 19 ms 924 KB
sample_02.txt AC 18 ms 792 KB
sample_03.txt AC 19 ms 924 KB
subtask1_01.txt AC 18 ms 928 KB
subtask1_02.txt AC 19 ms 840 KB
subtask1_03.txt AC 18 ms 916 KB
subtask1_04.txt AC 17 ms 796 KB
subtask1_05.txt AC 19 ms 800 KB
subtask1_06.txt AC 18 ms 800 KB
subtask1_07.txt AC 19 ms 920 KB
subtask1_08.txt AC 19 ms 796 KB
subtask1_09.txt AC 19 ms 796 KB
subtask1_10.txt AC 20 ms 796 KB
subtask1_11.txt AC 18 ms 800 KB
subtask1_12.txt AC 18 ms 916 KB
subtask2_01.txt AC 19 ms 800 KB
subtask2_02.txt AC 17 ms 800 KB
subtask2_03.txt AC 19 ms 800 KB
subtask2_04.txt AC 18 ms 916 KB
subtask2_05.txt AC 19 ms 800 KB
subtask2_06.txt AC 17 ms 844 KB
subtask2_07.txt AC 18 ms 920 KB
subtask2_08.txt AC 18 ms 912 KB
subtask2_09.txt AC 19 ms 800 KB
subtask2_10.txt AC 19 ms 800 KB
subtask2_11.txt AC 19 ms 796 KB
subtask2_12.txt AC 18 ms 872 KB
subtask3_01.txt AC 19 ms 800 KB
subtask3_02.txt AC 19 ms 792 KB
subtask3_03.txt AC 17 ms 796 KB
subtask3_04.txt AC 17 ms 888 KB
subtask3_05.txt AC 18 ms 800 KB
subtask3_06.txt AC 19 ms 796 KB
subtask3_07.txt AC 18 ms 920 KB
subtask3_08.txt AC 19 ms 924 KB
subtask3_09.txt AC 19 ms 800 KB
subtask3_10.txt AC 19 ms 924 KB
subtask3_11.txt AC 19 ms 800 KB
subtask3_12.txt AC 19 ms 800 KB