Submission #30922608


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}
std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);
template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}
template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
#include <iostream>
using i64 = long long;
template<i64 M> struct modint { i64 a;
  constexpr modint(const i64 x = 0): a((x%M+M)%M){}
  constexpr i64 value() const { return a; }
  constexpr modint inv() const { return this->pow(M-2); }
  constexpr modint pow(i64 r) const {
    modint ans(1); modint aa = *this;
    while(r) { if(r & 1) ans *= aa; aa *= aa; r >>= 1; }
    return ans;
  }
  constexpr bool operator==(const modint& r) const { return a == r.a; }
  constexpr bool operator!=(const modint& r) const { return a != r.a; }
  constexpr modint& operator=(const i64 r) { a = (r % M + M) % M; return *this; }
  constexpr modint& operator+=(const modint r) { a += r.a; if(a >= M) a -= M; return *this; }
  constexpr modint& operator-=(const modint r) { a -= r.a; if(a < 0) a += M; return *this; }
  constexpr modint& operator*=(const modint r) { a = a * r.a % M; return *this; }
  constexpr modint& operator/=(const modint r) { (*this) *= r.inv(); return *this; }
  constexpr modint operator+(const modint r) const { return modint(*this) += r; }
  constexpr modint operator-(const modint r) const { return modint(*this) -= r; }
  constexpr modint operator-() const { return modint(0) - modint(*this); }
  constexpr modint operator*(const modint r) const { return modint(*this) *= r; }
  constexpr modint operator/(const modint r) const { return modint(*this) /= r; }
  constexpr bool operator!=(const modint r) const { return this->value() != r.value(); }
};

template<const i64 M> std::ostream& operator<<(std::ostream& os, const modint<M>& m) { os << m.value(); return os; }

using fp = modint<(i64)(1e9+7)>;

int main() {
  i64 N, K, Q;
  cin >> N >> K >> Q;
  vector<i64> A(N);
  rep(i,0,N) {
    cin >> A[i];
    A[i]++;
  }

  vector<i64> R(Q), C(Q);
  rep(i,0,Q) cin >> R[i] >> C[i];
  vector<fp> dp(K + 1);
  dp[0] = 1;
  rep(i,0,N) {
    for(i64 j = K + 1; j --> A[i];) {
      dp[j] -= dp[j - A[i]];
    }
  }
  rep(i,0,N) {
    rep(j,1,K + 1) {
      dp[j] += dp[j - 1];
    }
  }
  vector<vector<pair<i64, i64>>> qry(N);
  rep(i,0,Q) {
    R[i]--;
    qry[R[i]].push_back( { C[i], i } );
  }

  vector<fp> ans(Q);

  rep(r,0,N) {
    vector<fp> nxt(K + 1);
    vector<fp> sum(A[r]);
    rep(i,0,K + 1) {
      sum[i % A[r]] += dp[i];
      nxt[i] = sum[i % A[r]];
    }
    for(i64 j = K + 1; j --> 1;) {
      nxt[j] -= nxt[j - 1];
    }
    for(auto [c, q]: qry[r]) {
      ans[q] = nxt[K - c];
    }
  }
  rep(i,0,Q) {
    cout << ans[i] << "\n";
  }
}

Submission Info

Submission Time
Task D - 注文の多い高橋商店
User niuez
Language C++ (GCC 9.2.1)
Score 100
Code Size 3872 Byte
Status AC
Exec Time 293 ms
Memory 29920 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:4:28: warning: unnecessary parentheses in declaration of ‘i’ [-Wparentheses]
    4 | #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
      |                            ^
./Main.cpp:67:3: note: in expansion of macro ‘rep’
   67 |   rep(i,0,N) {
      |   ^~~
./Main.cpp:4:28: warning: unnecessary parentheses in declaration of ‘i’ [-Wparentheses]
    4 | #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
      |                            ^
./Main.cpp:73:3: note: in expansion of macro ‘rep’
   73 |   rep(i,0,Q) cin >> R[i] >> C[i];
      |   ^~~
./Main.cpp:4:28: warning: unnecessary parentheses in declaration of ‘i’ [-Wparentheses]
    4 | #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
      |                            ^
./Main.cpp:76:3: note: in expansion of macro ‘rep’
   76 |   rep(i,0,N) {
      |   ^~~
./Main.cpp:4:28: warning: unnecessary parentheses in declaration of ‘i’ [-Wparentheses]
    4 | #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
      |                            ^
./Main.cpp:81:3: note: in expansion of macro ‘rep’
   81 |   rep(i,0,N) {
      |   ^~~
./Main.cpp:4:28: warning: unnecessary parentheses in declaration of ‘j’ [-Wparentheses]
    4 | #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
      |                            ^
./Main.cpp:82:5: note: in expansion of macro ‘rep’
   82 |     rep(j,1,K + 1) {
      |     ^~~
./Main.cpp:4:28: warning: unnecessary parentheses in declaration of ‘i’ [-Wparentheses]
    4 | #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
      |                            ^
./Main.cpp:87:3: note: in expansion of macro ‘rep’
   87 |   rep(i,0,Q) {
      |   ^~~
./Main.cpp:4:28: warning: unnecessary parentheses in declaration of ‘r’ [-Wparentheses]
    4 | #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
      |                            ^
./Main.cpp:94:3: note: in expansion of macro ‘rep’
   94 |   rep(r,0,N) {
      |   ^~...

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3 Subtask4
Score / Max Score 0 / 0 10 / 10 20 / 20 50 / 50 20 / 20
Status
AC × 2
AC × 10
AC × 13
AC × 13
AC × 23
Set Name Test Cases
Sample sample_01.txt, sample_02.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
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, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt
Subtask3 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, subtask3_01.txt, subtask3_02.txt, subtask3_03.txt
Subtask4 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, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask3_01.txt, subtask3_02.txt, subtask3_03.txt, subtask4_01.txt, subtask4_02.txt, subtask4_03.txt, subtask4_04.txt, subtask4_05.txt, subtask4_06.txt, subtask4_07.txt
Case Name Status Exec Time Memory
sample_01.txt AC 8 ms 3472 KiB
sample_02.txt AC 2 ms 3520 KiB
subtask1_01.txt AC 3 ms 3528 KiB
subtask1_02.txt AC 3 ms 3472 KiB
subtask1_03.txt AC 3 ms 3460 KiB
subtask1_04.txt AC 2 ms 3420 KiB
subtask1_05.txt AC 2 ms 3500 KiB
subtask1_06.txt AC 3 ms 3524 KiB
subtask1_07.txt AC 3 ms 3524 KiB
subtask1_08.txt AC 2 ms 3532 KiB
subtask2_01.txt AC 29 ms 5780 KiB
subtask2_02.txt AC 47 ms 7668 KiB
subtask2_03.txt AC 46 ms 7552 KiB
subtask3_01.txt AC 44 ms 3676 KiB
subtask3_02.txt AC 88 ms 3576 KiB
subtask3_03.txt AC 91 ms 3736 KiB
subtask4_01.txt AC 238 ms 28316 KiB
subtask4_02.txt AC 276 ms 29668 KiB
subtask4_03.txt AC 178 ms 27108 KiB
subtask4_04.txt AC 168 ms 22668 KiB
subtask4_05.txt AC 285 ms 29920 KiB
subtask4_06.txt AC 252 ms 27460 KiB
subtask4_07.txt AC 293 ms 29408 KiB