Submission #15551168


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}


const ll MOD = 1e9 + 7;

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint& operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}
  mint& operator-=(const mint a) {if ((x += MOD-a.x) >= MOD) x -= MOD;return *this;}
  mint& operator*=(const mint a) {(x *= a.x) %= MOD;return *this;}
  mint operator+(const mint a) const {mint res(*this);return res+=a;}
  mint operator-(const mint a) const {mint res(*this);return res-=a;}
  mint operator*(const mint a) const {mint res(*this);return res*=a;}
  mint pow(ll b) const {
    mint res(1), a(*this);
    while (b) {
      if (b & 1) res *= a;
      a *= a;
      b >>= 1;
    }
    return res;
  }
  // for prime MOD
  mint inv() const {return pow(MOD-2);}
  mint& operator/=(const mint a) {return (*this) *= a.inv();}
  mint operator/(const mint a) const {mint res(*this);return res/=a;}
};
ostream& operator<<(ostream& os, const mint& a) {os << a.x; return os;}


mint choose(int n, int r) {
  if (n < 0 || r < 0 || n < r) return 0;

  if (r > n-r) return choose(n, n-r);

  mint res = 1;
  for (int i = 0; i < r; i++) res *= (n - i);
  for (int i = 1; i <= r; i++) res /= i;

  return res;
}


mint ways(ll F, ll T, ll n) {

  // cout << F << " " << T << " " << n << endl;

  ll ball = T-F;
  ll wall = n;

  return choose(ball + wall, wall);
}



int main2() {
  int N = nextLong();
  vector<ll> a(N);
  REP(i, N) a[i] = nextLong();


  mint ans = 1;
  vector<int> t;
  REP(i, N) {
    if (a[i] != -1) {
      if (t.size() > 0) {
        t.push_back(a[i]);
        // pv(ALL(t));
        ans *= ways(t.front(), t.back(), t.size() - 2);
        t.clear();
      }
    }
    t.push_back(a[i]);
  }

  cout << ans << endl;
  return 0;
}

int main() {


#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Submission Info

Submission Time
Task C - タコヤ木
User hs484
Language C++ (GCC 9.2.1)
Score 100
Code Size 2480 Byte
Status AC
Exec Time 11 ms
Memory 3696 KB

Compile Error

./Main.cpp: In function ‘ll nextLong()’:
./Main.cpp:13:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   13 | ll nextLong() { ll x; scanf("%lld", &x); return x;}
      |                       ~~~~~^~~~~~~~~~~~

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3
Score / Max Score 0 / 0 50 / 50 30 / 30 20 / 20
Status
AC × 3
AC × 14
AC × 26
AC × 39
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
Subtask1 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 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 sample_01.txt, sample_02.txt, sample_03.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_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
Case Name Status Exec Time Memory
sample_01.txt AC 11 ms 3616 KB
sample_02.txt AC 2 ms 3656 KB
sample_03.txt AC 3 ms 3456 KB
subtask1_01.txt AC 3 ms 3656 KB
subtask1_02.txt AC 2 ms 3512 KB
subtask1_03.txt AC 3 ms 3604 KB
subtask1_04.txt AC 3 ms 3592 KB
subtask1_05.txt AC 2 ms 3616 KB
subtask1_06.txt AC 2 ms 3660 KB
subtask1_07.txt AC 2 ms 3640 KB
subtask1_08.txt AC 2 ms 3616 KB
subtask1_09.txt AC 2 ms 3468 KB
subtask1_10.txt AC 2 ms 3640 KB
subtask1_11.txt AC 4 ms 3616 KB
subtask1_12.txt AC 2 ms 3660 KB
subtask2_01.txt AC 3 ms 3640 KB
subtask2_02.txt AC 2 ms 3636 KB
subtask2_03.txt AC 2 ms 3592 KB
subtask2_04.txt AC 2 ms 3660 KB
subtask2_05.txt AC 2 ms 3668 KB
subtask2_06.txt AC 2 ms 3664 KB
subtask2_07.txt AC 3 ms 3696 KB
subtask2_08.txt AC 4 ms 3684 KB
subtask2_09.txt AC 3 ms 3616 KB
subtask2_10.txt AC 2 ms 3660 KB
subtask2_11.txt AC 5 ms 3656 KB
subtask2_12.txt AC 3 ms 3560 KB
subtask3_01.txt AC 2 ms 3636 KB
subtask3_02.txt AC 2 ms 3456 KB
subtask3_03.txt AC 2 ms 3564 KB
subtask3_04.txt AC 2 ms 3528 KB
subtask3_05.txt AC 2 ms 3608 KB
subtask3_06.txt AC 2 ms 3464 KB
subtask3_07.txt AC 4 ms 3692 KB
subtask3_08.txt AC 2 ms 3656 KB
subtask3_09.txt AC 2 ms 3656 KB
subtask3_10.txt AC 2 ms 3656 KB
subtask3_11.txt AC 2 ms 3604 KB
subtask3_12.txt AC 2 ms 3528 KB