結果

問題 No.2156 ぞい文字列
ユーザー 👑 bo9chanbo9chan
提出日時 2022-12-09 22:05:53
言語 C++23(draft)
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 18,604 bytes
コンパイル時間 2,471 ms
コンパイル使用メモリ 133,996 KB
最終ジャッジ日時 2023-08-04 23:46:50
合計ジャッジ時間 2,839 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In instantiation of ‘void print(const T&) [with T = atcoder::static_modint<998244353>]’:
main.cpp:290:10:   required from here
main.cpp:167:48: エラー: no match for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘const atcoder::static_modint<998244353>’)
  167 | template<class T> void print(const T& e) {cout << e << '\n';}
      |                                           ~~~~~^~~~
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/istream:39,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/sstream:38,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/bits/quoted_string.h:38,
         次から読み込み:  /usr/local/gcc7/include/c++/12.2.0/iomanip:45,
         次から読み込み:  main.cpp:12:
/usr/local/gcc7/include/c++/12.2.0/ostream:108:7: 備考: 候補: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ostream_type& (*)(__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>]’
  108 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |       ^~~~~~~~
/usr/local/gcc7/include/c++/12.2.0/ostream:108:36: 備考:   no known conversion for argument 1 from ‘const atcoder::static_modint<998244353>’ to ‘std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)’ {aka ‘std::basic_ostream<char>& (*)(std::basic_ostream<char>&)’}
  108 |       operator<<(__ostream_type& (*__pf)(__ostream_type&))
      |                  ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/local/gcc7/include/c++/12.2.0/ostream:117:7: 備考: 候補: ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(__ios_type& (*)(__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; __ostream_type = std::basic_ostream<char>; __ios_type = std

ソースコード

diff #

#ifdef __LOCAL
#include <mytemplate.hpp>  // プリコンパイル済みヘッダ ~/local/include/mytemplate.hpp.gch
#else
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream> 
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#endif
using namespace std;
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using int128 = __int128_t;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
#define REP1(i, n) REP3(i, 0, n, 1)
#define REP2(i, s, n) REP3(i, s, n, 1)
#define REP3(i, s, n, d) for(ll i = (ll)(s); i < (ll)(n); i += (d))
#define REP_OVERLOAD(e1, e2, e3, e4, NAME,...) NAME
#define rep(...) REP_OVERLOAD(__VA_ARGS__, REP3, REP2, REP1)(__VA_ARGS__)
#define DEP1(i, n) DEP3(i, n, -1, 1)
#define DEP2(i, n, s) DEP3(i, n, s, 1)
#define DEP3(i, n, s, d) for(ll i = (ll)(n); (ll)(s) < i; i -= (d))
#define DEP_OVERLOAD(e1, e2, e3, e4, NAME,...) NAME
#define dep(...) DEP_OVERLOAD(__VA_ARGS__, DEP3, DEP2, DEP1)(__VA_ARGS__)
#define fore(e, a) for (auto&& e: (a))
#define len(a) (ll)(a).size()
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define th third
#define sqrt(x) sqrtl(x)
#define popcount(b) __builtin_popcountll(b)
#define Bit(b, i) (((b) >> (i)) & 1)
#define End(...) do{ print(__VA_ARGS__); exit(0); }while(0)
/*********    C O N S T A N T    **********/
constexpr ll INF = LONG_LONG_MAX / 2 - 10000LL;  // 4,611,686,018,427,377,903  ~= 4.6e+18, 19桁
const double PI = acos(-1);
/*********       P A I R       **********/
template<class T, class U> inline pair<T, U>& operator+=(pair<T, U>& a, const pair<T, U>& b) {a.fi += b.fi; a.se += b.se; return a;}
template<class T, class U> inline pair<T, U>& operator-=(pair<T, U>& a, const pair<T, U>& b) {a.fi -= b.fi; a.se -= b.se; return a;}
template<class T, class U> inline pair<T, U>& operator*=(pair<T, U>& a, const pair<T, U>& b) {a.fi *= b.fi; a.se *= b.se; return a;}
template<class T, class U> inline pair<T, U>& operator/=(pair<T, U>& a, const pair<T, U>& b) {a.fi /= b.fi; a.se /= b.se; return a;}
template<class T, class U> inline pair<T, U>& operator%=(pair<T, U>& a, const pair<T, U>& b) {a.fi %= b.fi; a.se %= b.se; return a;}
template<class T, class U, class V> inline pair<T, U>& operator+=(pair<T, U>& a, const V& b) {a.fi += b; a.se += b; return a;}
template<class T, class U, class V> inline pair<T, U>& operator-=(pair<T, U>& a, const V& b) {a.fi -= b; a.se -= b; return a;}
template<class T, class U, class V> inline pair<T, U>& operator*=(pair<T, U>& a, const V& b) {a.fi *= b; a.se *= b; return a;}
template<class T, class U, class V> inline pair<T, U>& operator/=(pair<T, U>& a, const V& b) {a.fi /= b; a.se /= b; return a;}
template<class T, class U, class V> inline pair<T, U>& operator%=(pair<T, U>& a, const V& b) {a.fi %= b; a.se %= b; return a;}
template<class T, class U, class V> inline pair<T, U> operator+(pair<T, U> a, const V& b) {a += b; return a;}
template<class T, class U, class V> inline pair<T, U> operator-(pair<T, U> a, const V& b) {a -= b; return a;}
template<class T, class U, class V> inline pair<T, U> operator*(pair<T, U> a, const V& b) {a *= b; return a;}
template<class T, class U, class V> inline pair<T, U> operator/(pair<T, U> a, const V& b) {a /= b; return a;}
template<class T, class U, class V> inline pair<T, U> operator%(pair<T, U> a, const V& b) {a %= b; return a;}
template<class T, class U> inline pair<T, U> operator+(pair<T, U> a) {return a;}
template<class T, class U> inline pair<T, U> operator-(pair<T, U> a) {return a * (-1);}
template<class T, class U> istream& operator >>(istream& stream, pair<T, U>& a) {stream >> a.fi >> a.se; return stream;}
template<class T, class U> ostream& operator <<(ostream &stream, const pair<T, U>& a) { stream << a.fi << " " << a.se; return stream; }
/*********       V E C T O R      **********/
template<class T> inline vector<T>& operator+=(vector<T>& a, const vector<T>& b) {assert(a.size() == b.size()); rep(i, 0, a.size()) a[i] += b[i]; return a;}
template<class T> inline vector<T>& operator-=(vector<T>& a, const vector<T>& b) {assert(a.size() == b.size()); rep(i, 0, a.size()) a[i] -= b[i]; return a;}
template<class T> inline vector<T>& operator*=(vector<T>& a, const vector<T>& b) {assert(a.size() == b.size()); rep(i, 0, a.size()) a[i] *= b[i]; return a;}
template<class T> inline vector<T>& operator/=(vector<T>& a, const vector<T>& b) {assert(a.size() == b.size()); rep(i, 0, a.size()) a[i] /= b[i]; return a;}
template<class T> inline vector<T>& operator%=(vector<T>& a, const vector<T>& b) {assert(a.size() == b.size()); rep(i, 0, a.size()) a[i] %= b[i]; return a;}
template<class T, class U> inline vector<T>& operator+=(vector<T>& a, const U& b) {fore(e, a) e += b; return a;}
template<class T, class U> inline vector<T>& operator-=(vector<T>& a, const U& b) {fore(e, a) e -= b; return a;}
template<class T, class U> inline vector<T>& operator*=(vector<T>& a, const U& b) {fore(e, a) e *= b; return a;}
template<class T, class U> inline vector<T>& operator/=(vector<T>& a, const U& b) {fore(e, a) e /= b; return a;}
template<class T, class U> inline vector<T>& operator%=(vector<T>& a, const U& b) {fore(e, a) e %= b; return a;}
template<class T, class U> inline vector<T> operator+(vector<T> a, const U& b) {a += b; return a;}
template<class T, class U> inline vector<T> operator-(vector<T> a, const U& b) {a -= b; return a;}
template<class T, class U> inline vector<T> operator*(vector<T> a, const U& b) {a *= b; return a;}
template<class T, class U> inline vector<T> operator/(vector<T> a, const U& b) {a /= b; return a;}
template<class T, class U> inline vector<T> operator%(vector<T> a, const U& b) {a %= b; return a;}
template<class T> inline vector<T> operator+(vector<T> a) {return a;}
template<class T> inline vector<T> operator-(vector<T> a) {return a * (-1);}
template<class T> istream& operator >>(istream& stream, vector<T>& a) {fore(e, a) stream >> e; return stream;}
template<class T> ostream& operator <<(ostream& stream, const vector<T>& v) {if(v.size()){stream << v[0]; rep(i, 1, v.size()) cout << " " << v[i];} return stream;}
template<class T> ostream& operator <<(ostream& stream, const vector<vector<T>>& vv) {if(vv.size()){stream << vv[0]; rep(i, 1, vv.size()) cout << '\n' << vv[i];} return stream;}
template<class T> inline T Sum(const vector<T>& v) {return reduce(all(v));}
template<class T> inline T Max(const vector<T>& v) {return *max_element(all(v));}
template<class T> inline T Min(const vector<T>& v) {return *min_element(all(v));}
template<class T> inline ll Argmax(const vector<T>& v) {return max_element(all(v)) - v.begin();}
template<class T> inline ll Argmin(const vector<T>& v) {return min_element(all(v)) - v.begin();}
template<class T, class U> inline bool Contains(const vector<T>& v, const U& a) {return find(all(v), a) != v.end();}
template<class T, class U> vector<T> make_vector(int n, U v) { return vector<T>(n, v); }
template <class T, class... Args> auto make_vector(int n, Args... args) {auto val = make_vector<T>(args...); return make_vector<decltype(val)>(n, move(val));}
/*********        S E T        **********/
template<class T> istream& operator >>(istream& stream, set<T>& st) {T e; stream >> e; st.insert(e); return stream;}
template<class T> ostream& operator <<(ostream& stream, const set<T>& st) {if(st.size()){auto it=st.begin(); stream << *it++; for(; it!=st.end(); it++) cout << " " << *it;} return stream;}
template<class T> inline T Max(const set<T>& st) {return *prev(st.end());}
template<class T> inline T Min(const set<T>& st) {return *st.begin();}
template<class T> inline bool Contains(const set<T>& st, T x) {return st.find(x) != st.end();}
/*********   M U L T I S E T   **********/
template<class T> istream& operator >>(istream& stream, multiset<T>& st) {T e; stream >> e; st.insert(e); return stream;}
template<class T> ostream& operator <<(ostream& stream, const multiset<T>& st) {if(st.size()){auto it=st.begin(); stream << *it++; for(; it!=st.end(); it++) cout << " " << *it;} return stream;}
template<class T> inline T Max(const multiset<T>& st) {return *prev(st.end());}
template<class T> inline T Min(const multiset<T>& st) {return *st.begin();}
template<class T> inline bool Contains(const multiset<T>& st, T x) {return st.find(x) != st.end();}
template<class T> inline bool EraseOne(multiset<T>& st, T x) {auto it=st.find(x); if (it!=st.end()) {st.erase(it); return true;} else return false;}  // 要素xを1つ削除. 消せたらtrueを返す.
/*********     S T R I N G     **********/
template<class T> inline bool Contains(const string& s, const T& c) {return s.find(c) != string::npos;}  // cはchar, string共に可
inline string ToUpper(const string& s) {string t; t.resize(s.size()); std::transform(all(s), t.begin(), ::toupper); return t; }
inline string ToLower(const string& s) {string t; t.resize(s.size()); std::transform(all(s), t.begin(), ::tolower); return t; }
/*********       T R I O       **********/
template<class T1, class T2, class T3> struct trio {
    T1 first; T2 second; T3 third;
    // コンストラクタ・代入演算子
    trio() {first=T1(); second=T2(); third=T3();}
    trio(const T1& x) : first(x), second(x), third(x) {}
    trio(const T1& x, const T2& y, const T3& z) : first(x), second(y), third(z) {}
    trio(const trio& t) {first=t.first; second=t.second; third=t.third;}  // コピーコンストラクタ
    trio& operator =(const trio& t) {first=t.first; second=t.second; third=t.third; return *this;}
    // 比較演算子
    bool operator <(const trio& t) const {return tie(first, second, third) < tie(t.first, t.second, t.third);}
    bool operator ==(const trio& t) const {return tie(first, second, third) == tie(t.first, t.second, t.third);}
    bool operator !=(const trio& other) const { return !(*this == other); }
    bool operator >(const trio& other) const { return other < *this; }
    bool operator <=(const trio& other) const { return !(*this > other); }
    bool operator >=(const trio& other) const { return !(*this < other); }
    // 単項演算子(+ -)
    trio operator +() const { return *this; }
    trio operator -() const { return (-1) * (*this); }
    // 複合代入演算子
    trio& operator +=(const trio& t) {first += t.first; second += t.second; third += t.third; return *this;}
    trio& operator -=(const trio& t) {first -= t.first; second -= t.second; third -= t.third; return *this;}
    trio& operator *=(const trio& t) {first *= t.first; second *= t.second; third *= t.third; return *this;}
    trio& operator /=(const trio& t) {first /= t.first; second /= t.second; third /= t.third; return *this;}
    trio& operator %=(const trio& t) {first %= t.first; second %= t.second; third %= t.third; return *this;}
    // 算術演算子
    friend trio operator +(const trio& lhs, const trio& rhs) {return trio(lhs) += rhs;}
    friend trio operator -(const trio& lhs, const trio& rhs) {return trio(lhs) -= rhs;}
    friend trio operator *(const trio& lhs, const trio& rhs) {return trio(lhs) *= rhs;}
    friend trio operator /(const trio& lhs, const trio& rhs) {return trio(lhs) /= rhs;}
    friend trio operator %(const trio& lhs, const trio& rhs) {return trio(lhs) %= rhs;}
    // 入出力
    friend istream& operator >>(istream &stream, trio& t) {return stream >> t.first >> t.second >> t.third;}
    friend ostream& operator <<(ostream &stream, const trio& t) {return stream << t.first << " " << t.second << " " << t.third;}
};
using tll = trio<ll, ll, ll>;
/*********       P R I N T       **********/
template<class T> void print(const T& e) {cout << e << '\n';}
template<class H, class... T> void print(const H& h, const T&... t) {cout << h << ' '; print(t...);}
/*********       D E B U G       **********/
#ifdef __LOCAL
#define debug(...) if(DEBUG) do{cout << '[' << #__VA_ARGS__ << "] ";debug_(__VA_ARGS__);}while(0)
#else
#define debug(...)
#endif
void dbg_(const long long& e) {if (e == INF) cout << "INF"; else if (e == -INF) cout << "-INF"; else cout << e;}
template<class T> void dbg_(const T& e) {cout << e;}
template<class T, class U> void dbg_(const pair<T, U>& p) {cout << '('; dbg_(p.first); cout << ' '; dbg_(p.second); cout << ')';}
template<class T1, class T2, class T3> void dbg_(const trio<T1, T2, T3>& t) {cout << '('; dbg_(t.first); cout << ' '; dbg_(t.second); cout << ' '; dbg_(t.third); cout << ')';}
template<class T> void debug_(const T& e) {dbg_(e); cout << '\n';}
template<class T> void debug_(const vector<T>& v) {if (v.size()){auto it=v.begin(); dbg_(*it++); for(; it!=v.end(); ++it){cout << ' '; dbg_(*it);}} cout << '\n';}
template<class T> void debug_(const vector<vector<T>>& vv) {cout << '\n'; ll cnt=0; for(auto&& v : vv){cout << cnt++ << ": "; debug_(v);}}
template<class T, class U> void debug_(const map<T, U>& mp) {if (mp.size()) {auto it = mp.begin(); dbg_(*it++); for(; it != mp.end(); ++it) {cout << ' '; dbg_(*it);}} cout << '\n';}
template<class T, class U> void debug_(const vector<map<T, U>>& vm){cout << '\n'; ll cnt=0; for(auto&& mp : vm){cout << cnt++ << ": "; debug_(mp);}}
template<class T> void debug_(const set<T>& st) {if(st.size()){auto it=st.begin(); dbg_(*it++); for(; it!=st.end(); ++it) {cout << ' '; dbg_(*it);}}cout << '\n';}
template<class T> void debug_(const multiset<T>& st) {if(st.size()) {auto it=st.begin(); dbg_(*it++); for(; it != st.end(); ++it) {cout << ' '; dbg_(*it);}} cout << '\n';}
template<class T> void debug_(const vector<set<T>>& vs) {cout << '\n'; ll cnt=0; for(auto&& st : vs){cout << cnt++ << ": "; debug_(st);}}
template<class T> void debug_(const vector<multiset<T>>& vs) {cout << '\n'; ll cnt=0;for(auto&& st : vs){cout << cnt++ << ": "; debug_(st);}}
template<class H, class... T> void debug_(const H& h, const T&... t) {dbg_(h); cout << ", "; debug_(t...);}
/*********       O T H E R S       **********/
template<class T, class U> inline bool chmin(T& a, U b) {if (a > b) {a = b; return true;} return false;}  // bは値渡し!
template<class T, class U> inline bool chmax(T& a, U b) {if (a < b) {a = b; return true;} return false;}
template<class T, class U> inline auto Mod(const T& a, const U& m) {return (a % m + m) % m;}  // 負もOK
template<class T, class U> inline auto Ceil(const T& x, const U& y) {return x < 0 ? x/y : (x + y - 1) / y;}  // 負もOK
template<class T, class U> inline auto Floor(const T& x, const U& y) {return -(Ceil(-x, y)); }  // 負もOK
template<class T> inline T Pow(T x, ll n) {assert(n >= 0); T ret = 1; while(n) {if (n % 2) ret *= x; x = x * x; n /= 2;} return ret;}  // べき乗 mintもOK
template<class T> inline T Aseries(T a, T d, ll n) {assert(n >= 0); return a * n + n * (n - 1) / 2 * d;}  // 等差級数 mintもOK
template<class T> inline T Gseries(T a, T r, ll n) {assert(n >= 0); if (r == 1) return a * n; else return a * (1 - Pow(r, n)) / (1 - r);}  // 等比級数 mintもOK
template<class T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
inline ll Mask(ll n) {assert(0 <= n && n < 63); return (1LL << n) - 1LL;}  // [0, n)のbitが立った64bit整数を返す。
inline ll Mask(ll n, ll m) {assert(n >= m); return Mask(n) ^ Mask(m);}  // [m, n)のbitが立った64bit整数を返す。
/*********       M  O  D       **********/
#include <atcoder/modint>  // https://atcoder.github.io/ac-library/production/document_ja/
using namespace atcoder;
using mint = modint998244353;     // modint1000000007;
istream& operator >>(istream& stream, mint& e) {ll n; stream >> n; e = n; return stream; }
ostream& operator <<(ostream& stream, const mint& e) { stream << e.val(); return stream; }
using vm = vector<mint>;
using vvm = vector<vm>;
/***************************************/
constexpr bool DEBUG = true;

template <class T> using matrix = vector<vector<T>>;
// 2次元ベクトルを時計周りに90°回転, O(N^2)
template<class T> matrix<T> RotateClockwise(const matrix<T>& A) {
    ll r = len(A);  // Aの行数
    ll c = len(A[0]);  // Aの列数
    swap(r, c);  // 入れ替え
    matrix<T> B(r, vector<T>(c));  // 新しくベクトルを定義
    rep(i, r) rep(j, c) B[i][j] = A[c - j - 1][i];  // 値を代入
    return B;
}

// 2次元ベクトルを転置, O(N^2)
template<class T> matrix<T> Transpose(const matrix<T>& A) {
    ll r = len(A);  // Aの行数
    ll c = len(A[0]);  // Aの列数
    swap(r, c);  // 入れ替え
    matrix<T> B(r, vector<T>(c));  // 新しくベクトルを定義
    rep(i, r) rep(j, c) B[i][j] = A[j][i];  // 値を代入
    return B;
}

/* 2次元ベクトルの行列積を計算  参考:https://qiita.com/ageprocpp/items/7bda728d109c953ece3c
Examples:
    vvl C = Mul(A, B);  */
template<class T> matrix<T> Mul(const matrix<T>& A, const matrix<T>& B) {
    ll r1 = len(A), c1 = len(A[0]);
    ll r2 = len(B), c2 = len(B[0]);
    assert(c1 == r2);
    matrix<T> C(r1, vector<T>(c2));
    rep(i, r1) {
        rep(k, c1) {
            rep(j, c2) {
                C[i][j] += A[i][k] * B[k][j];
            }
        }
    }
    return C;
}

template<class T> vector<T> Mul(const matrix<T>& A, const vector<T>& b) {
    assert(len(A[0]) == len(b));
    matrix<T> B(len(b), vector<T>(1));
    rep(i, 0, len(b)) B[i][0] = b[i];
    matrix<T> C = Mul(A, B);
    return Transpose(C)[0];
}

template<class T> vector<T> Mul(const vector<T>& a, const matrix<T>& B) {
    assert(len(a) == len(B));
    matrix<T> A(1, vector<T>(len(a)));
    rep(i, len(a)) A[0][i] = a[i];
    return Mul(A, B)[0];
}

/* 行列の累乗 A^n を計算(mul関数を使用)
Examples:
    vvl B = Pow(A, 5);  */
template<class T> matrix<T> Pow(matrix<T> A, ll n) {
    ll r = len(A);
    assert(r == len(A[0]));
    // Aと同じサイズの行列Bを単位行列として作成
    matrix<T> B(r, vector<T>(r, 0));
    rep(i, r) B[i][i] = 1;
    // 繰り返し二乗法により計算
    while (n > 0) {
        if (n & 1) B = Mul(A, B);
        A = Mul(A, A);
        n >>= 1;
    }
    return B;
}

int main() {
    ll N;
    cin >> N;
    vvm A = {{1, 1}, {1, 0}};
    vm x = {1, 0};
    auto ans = Mul(Pow(A, N - 1), x);
    print(Sum(ans) - 1);
}


0