結果

問題 No.997 Jumping Kangaroo
ユーザー ganmodokixganmodokix
提出日時 2019-11-01 20:29:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 8,668 bytes
コンパイル時間 2,324 ms
コンパイル使用メモリ 172,308 KB
最終ジャッジ日時 2023-10-13 00:59:05
合計ジャッジ時間 3,390 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/gthr.h:148,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ext/atomicity.h:35,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/bits/ios_base.h:39,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ios:42,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/istream:38,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/sstream:38,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/complex:45,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/ccomplex:39,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:54,
         次から読み込み:  main.cpp:7:
/usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/gthr-default.h:102:1: エラー: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  102 | __gthrw(pthread_once)
      | ^~~~~~~
/usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/gthr-default.h:102:1: エラー: attribute value ‘tune=native’ was already specified in ‘target’ attribute
/usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/gthr-default.h:103:1: エラー: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  103 | __gthrw(pthread_getspecific)
      | ^~~~~~~
/usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/gthr-default.h:103:1: エラー: attribute value ‘tune=native’ was already specified in ‘target’ attribute
/usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/gthr-default.h:104:1: エラー: attribute value ‘tune=native’ was already specified in ‘target’ attribute
  104 | __gthrw(pthread_setspecific)
      | ^~~~~~~
/usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/gthr-default.h:104:1: エラー: attribute value ‘tune=native’ was already

ソースコード

diff #

// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>
#include <chrono>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール

// 行列演算
// pdivの余りを取りたくない場合はoperator+=/-=/*のコメントアウトを適宜
constexpr ll pdiv = 1000000007LL;

template <typename T = ll>
class matrix {
private:
    size_t col_size, row_size;
    vector<T> raw;
public:
    matrix() : col_size(0), row_size(0), raw() {}
    matrix(size_t n) : col_size(1), row_size(n), raw(n, 0) {}
    matrix(size_t n, size_t m) : col_size(m), row_size(n), raw(n * m, 0) {}
    matrix(const vector<vector<T>> &a) : col_size(a.size() ? a[0].size() : 0), row_size(a.size()), raw(col_size * row_size) {
        for (size_t i = 0; i < row_size; i++) {
            for (size_t j = 0; j < col_size; j++) {
                at(i, j) = a[i][j];
            }
        }
    }
    matrix(initializer_list<T> init) : col_size(init.size()), row_size(1), raw(init) {}
    matrix(initializer_list<initializer_list<T>> init) : col_size(0), row_size(0), raw() {
        const size_t n = init.size();
        const size_t m = [&]() {
            size_t maxm = 0;
            for (const auto& initi : init) {
                const size_t mi = initi.size();
                if (mi > maxm) maxm = mi;
            }
            return maxm;
        }();
        tie(row_size, col_size) = make_pair(n, m);
        raw.resize(n * m);
        size_t i = 0, j = 0;
        for (const auto &initi : init) {
            for (const auto &v : initi) {
                at(i, j++) = v;
            }
            i++; j = 0;
        }
    }
    size_t rows() const { return row_size; }
    size_t cols() const { return col_size; }
    const T& at(const size_t i, const size_t j) const { return raw.at(i * col_size + j); }
    const T& at(const size_t i) const { return raw.at(i); }
    T& at(const size_t i, const size_t j) { return raw.at(i * col_size + j); }
    T& at(const size_t i) { return raw.at(i); }
    T& operator() (size_t i, size_t j) { return raw[i * col_size + j]; }
    T& operator() (size_t i) { return raw[i]; }
    T& operator[] (size_t i) { return raw[i]; }
    const T& operator() (size_t i, size_t j) const { return raw[i * col_size + j]; }
    const T& operator() (size_t i) const { return raw[i]; }
    const T& operator[] (size_t i) const { return raw[i]; }
    matrix<T>& operator+= (const matrix<T> &a) {
        for (size_t i = 0; i < row_size; i++) {
            for (size_t j = 0; j < col_size; j++) {
                // at(i, j) += a.at(i, j);
                if ((at(i, j) += a.at(i, j)) >= pdiv) at(i, j) -= pdiv;
            }
        }
        return *this;
    }
    matrix<T>& operator-= (const matrix<T> &a) {
        for (size_t i = 0; i < row_size; i++) {
            for (size_t j = 0; j < col_size; j++) {
                // at(i, j) -= a.at(i, j);
                if ((at(i, j) +=  pdiv - a.at(i, j)) >= pdiv) at(i, j) -= pdiv;
            }
        }
        return *this;
    }
    matrix<T> operator* (const matrix<T> &a) {
        assert(col_size == a.row_size);
        const size_t n = row_size, m = col_size, q = a.col_size;
        matrix<T> r(n, q);
        for (size_t i = 0; i < n; i++) {
            for (size_t k = 0; k < m; k++) {
                for (size_t j = 0; j < q; j++) {
                    // r.at(i, j) += at(i, k) * a.at(k, j);
                    (r.at(i, j) += at(i, k) * a.at(k, j) % pdiv) %= pdiv;
                }
            }
        }
        return r;
    }
    
    matrix<T> operator+ (const matrix<T> &a) {
        matrix<T> r = *this;
        return r += a;
    }
    matrix<T> operator- (const matrix<T> &a) {
        matrix<T> r = *this;
        return r -= a;
    }
    matrix<T>& operator*= (const matrix<T> &a) {
        return *this = move(*this * a);
    }
    operator T () const {
        assert(col_size == 1 && row_size == 1);
        return raw[0];
    }
    static matrix<T> eye(size_t n) {
        matrix<T> r(n, n);
        for (size_t i = 0; i < n; i++)
            r.at(i, i) = 1;
        return r;
    }
    matrix<T> transpose() {
        matrix<T> r(col_size, row_size);
        for (size_t i = 0; i < col_size; i++) {
            for (size_t j = 0; j < row_size; j++) {
                r.at(i, j) = at(j, i);
            }
        }
        return r;
    }
    matrix<T> pow(long long int n) {
        assert(row_size == col_size);
        matrix<T> r = eye(row_size);
        matrix<T> a = *this;
        while (n) {
            if (n & 1) r *= a;
            n /= 2;
            if (n) a *= a;
        }
        return r;
    }
};
template <typename T>
void DUMPMTR(matrix<T> m) {
    cerr << "[DEBUG] DUMPMTR: " << endl;
    for (size_t i = 0; i < m.rows(); i++) {
        cerr << " ["[!i] << "[";
        for (size_t j = 0; j < m.cols(); j++) {
            cerr << setw(4) << m(i, j) << " ]"[j+1 == m.cols()];
        }
        if (i+1 == m.rows()) cerr << ']';
        cerr << endl;
    }
}

// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n, w, k; cin >> n >> w >> k;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    // auto stime = chrono::system_clock::now();
    
    matrix<ll> x0((w+1)*2, 1), b((w+1)*2, (w+1)*2);
    x0(w) = 1;

    b(0, w) = 1;
    ll lp = w + 1;
    RANGE(i, w+1, w*2) {
        ll i2 = i - w;
        for (ll d : a) {
            ll j = i - d;
            if (j < 0) continue;
            if (j <= w) {
                if (i % w == 0) {
                    ++b(i2, j) %= pdiv;
                    ++b(i2, j + lp) %= pdiv;
                } else if (j < w) {
                    ++b(i2 + lp, j) %= pdiv;
                } else {
                    ++b(i2, j) %= pdiv;
                }
            } else {
                ll j2 = j - w;
                if (i % w == 0) {
                    REP(k, (w+1)*2) {
                        (b(i2, k) += b(j2, k)) %= pdiv;
                        (b(i2, k) += b(j2 + lp, k)) %= pdiv;
                    }
                } else {
                    REP(k, (w+1)*2) {
                        (b(i2, k) += b(j2, k)) %= pdiv;
                        (b(i2 + lp, k) += b(j2 + lp, k)) %= pdiv;
                    }
                }
            }
        }
    }

    // DUMPMTR(b);
    cout << (b.pow(k) * x0)[w] << endl;

    // auto etime = chrono::system_clock::now();
    // auto dur = chrono::duration_cast<chrono::milliseconds>(etime - stime).count();
    // cerr << "[DEBUG] done in " << dur << "ms\n";
    
}
0