結果
| 問題 | No.1595 The Final Digit |
| コンテスト | |
| ユーザー |
tomo0608
|
| 提出日時 | 2021-07-09 21:43:37 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 9,261 bytes |
| コンパイル時間 | 2,679 ms |
| コンパイル使用メモリ | 234,244 KB |
| 最終ジャッジ日時 | 2025-01-22 21:18:52 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In instantiation of ‘void print(const T&, const Ts& ...) [with T = atcoder::dynamic_modint<-1>; Ts = {}]’:
main.cpp:186:10: required from here
main.cpp:40:75: error: no match for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘const atcoder::dynamic_modint<-1>’)
40 | template<class T, class... Ts>void print(const T& a, const Ts&... b){cout << a; (cout << ... << (cout << ' ', b)); cout << '\n';}
| ~~~~~^~~~
In file included from /usr/include/c++/13/istream:41,
from /usr/include/c++/13/sstream:40,
from /usr/include/c++/13/complex:45,
from /usr/include/c++/13/ccomplex:39,
from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:127,
from main.cpp:7:
/usr/include/c++/13/ostream:110:7: note: candidate: ‘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>]’
110 | operator<<(__ostream_type& (*__pf)(__ostream_type&))
| ^~~~~~~~
/usr/include/c++/13/ostream:110:36: note: no known conversion for argument 1 from ‘const atcoder::dynamic_modint<-1>’ to ‘std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&)’ {aka ‘std::basic_ostream<char>& (*)(std::basic_ostream<char>&)’}
110 | operator<<(__ostream_type& (*__pf)(__ostream_type&))
| ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/ostream:119:7: note: candidate: ‘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::bas
ソースコード
/**
* author: tomo0608
* created: 09.07.2021 21:35:40
**/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include<atcoder/all>
using namespace atcoder;
#endif
typedef long long ll;
typedef long double ld;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define all(x) x.begin(),x.end()
#define rep1(a) for(long long i = 0; i < a; i++)
#define rep2(i, a) for(long long i = 0; i < a; i++)
#define rep3(i, a, b) for(long long i = a; i < b; i++)
#define rep4(i, a, b, c) for(long long i = a; i < b; i += c)
#define drep1(a) for(long long i = a-1; i >= 0; i--)
#define drep2(i, a) for(long long i = a-1; i >= 0; i--)
#define drep3(i, a, b) for(long long i = a-1; i >= b; i--)
#define drep4(i, a, b, c) for(long long i = a-1; i >= b; i -= c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define drep(...) overload4(__VA_ARGS__, drep4, drep3, drep2, drep1)(__VA_ARGS__)
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
template<class... T>void input(T&... a){(cin >> ... >> a);};
#define INT(...) int __VA_ARGS__; input(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__; input(__VA_ARGS__)
#define STRING(...) string __VA_ARGS__; input(__VA_ARGS__)
void print(){cout << '\n';}
template<class T, class... Ts>void print(const T& a, const Ts&... b){cout << a; (cout << ... << (cout << ' ', b)); cout << '\n';}
template<class T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T1, class T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
template<typename T> ostream& operator << (ostream& os, set<T>& set_var) {os << "{"; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {os << *itr;++itr;if(itr != set_var.end()) os << ", ";itr--;}os << "}";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) {os << "{";for(auto itr = map_var.begin(); itr != map_var.end(); itr++) {os << *itr;itr++;if (itr != map_var.end()) os << ", ";itr--;}os << "}";return os;}
#ifdef __LOCAL
void debug_out(){ cerr << endl;}
template < class Head, class... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...);}
#define debug(...) cerr << 'L' << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << 'L' << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
template<class T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
#define mp make_pair
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
template <typename T>T mypow(T x, ll n){T ret = 1;while(n > 0){if(n & 1)(ret *= x);(x *= x);n >>= 1;}return ret;}
#define endl '\n'
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
// input and output of modint
#include<atcoder/modint>
istream &operator>>(istream &is, atcoder::modint998244353 &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const atcoder::modint998244353 &a) { return os << a.val(); }
istream &operator>>(istream &is, atcoder::modint1000000007 &a) { long long v; is >> v; a = v; return is; }
ostream &operator<<(ostream &os, const atcoder::modint1000000007 &a) { return os << a.val(); }
template<int m> istream &operator>>(istream &is, atcoder::static_modint<m> &a) { long long v; is >> v; a = v; return is; }
template<int m> ostream &operator<<(ostream &os, const atcoder::static_modint<m> &a) { return os << a.val(); }
template<int m> istream &operator>>(istream &is, atcoder::dynamic_modint<m> &a) { long long v; is >> v; a = v; return is; }
template<int m> ostream &operator<<(ostream &os, const atcoder::dynamic_modint<m> &a) { return os << a.val(); }
// Binomial Coefficient of modint
template<class T> struct BiCoef {
vector<T> fact_, inv_, finv_;
constexpr BiCoef() {}
constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1){
init(n);
}
constexpr void init(int n) noexcept {
fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
int MOD = fact_[0].mod();
for(int i = 2; i < n; i++){
fact_[i] = fact_[i-1]*i;
inv_[i] = -inv_[MOD%i]*(MOD/i);
finv_[i] = finv_[i-1]*inv_[i];
}
}
constexpr T com(int n, int k) const noexcept {
if(n < k || n < 0 || k < 0)return 0;
return fact_[n]*finv_[k]*finv_[n-k];
}
constexpr T perm(int n, int k) const noexcept {
if(n < k || n < 0 || k < 0)return 0;
return fact_[n]*finv_[n-k];
}
constexpr T fact(int n) const noexcept {
if(n < 0)return 0;
return fact_[n];
}
constexpr T inv(int n) const noexcept {
if(n < 0)return 0;
return inv_[n];
}
constexpr T finv(int n) const noexcept {
if(n < 0)return 0;
return finv_[n];
}
};
//typedef atcoder::modint1000000007 mint;
//typedef atcoder::modint998244353 mint;
template< class T >// int, long long, atcoder::modint
struct Matrix {
vector< vector< T > > A;
//constructor
Matrix() {}
Matrix(size_t n, size_t m) : A(n, vector< T >(m, 0)) {}
Matrix(size_t n) : A(n, vector< T >(n, 0)) {};
size_t height() const {return (A.size());}
size_t width() const {return (A[0].size());}
inline const vector< T > &operator[](int k) const {return (A.at(k));}
inline vector< T > &operator[](int k) {return (A.at(k));}
static Matrix I(size_t n) {
Matrix mat(n);
for(int i = 0; i < n; i++) mat[i][i] = 1;
return (mat);
}
Matrix &operator+=(const Matrix &B) {size_t n = height(), m = width();assert(n == B.height() && m == B.width());for(int i = 0; i < n; i++)for(int j = 0; j < m; j++)(*this)[i][j] += B[i][j];return (*this);}
Matrix &operator-=(const Matrix &B) {size_t n = height(), m = width();assert(n == B.height() && m == B.width());for(int i = 0; i < n; i++)for(int j = 0; j < m; j++)(*this)[i][j] -= B[i][j];return (*this);}
Matrix &operator*=(const Matrix &B) {size_t n = height(), m = B.width(), p = width();assert(p == B.height());vector< vector< T > > C(n, vector< T >(m, 0));for(int i = 0; i < n; i++)for(int j = 0; j < m; j++)for(int k = 0; k < p; k++)C[i][j] = (C[i][j] + (*this)[i][k] * B[k][j]);A.swap(C);return (*this);}
Matrix &operator^=(long long k) {Matrix B = Matrix::I(height());while(k > 0) {if(k & 1) B *= *this;*this *= *this;k >>= 1LL;}A.swap(B.A);return (*this);}
Matrix operator+(const Matrix &B) const {return (Matrix(*this) += B);}
Matrix operator-(const Matrix &B) const {return (Matrix(*this) -= B);}
Matrix operator*(const Matrix &B) const {return (Matrix(*this) *= B);}
Matrix operator^(const long long k) const {return (Matrix(*this) ^= k);}
friend ostream &operator<<(ostream &os, Matrix &p) {size_t n = p.height(), m = p.width();for(int i = 0; i < n; i++) {os << "[";for(int j = 0; j < m; j++) {os << p[i][j] << (j + 1 == m ? "]\n" : ",");}}return (os);}
T determinant() {
Matrix B(*this);
assert(width() == height());
T ret = 1;
for(int i = 0; i < width(); i++) {
int idx = -1;
for(int j = i; j < width(); j++) {
if(B[j][i] != 0) idx = j;
}
if(idx == -1) return (0);
if(i != idx) {
ret *= -1;
swap(B[i], B[idx]);
}
ret *= B[i][i];
T vv = B[i][i];
for(int j = 0; j < width(); j++) {
B[i][j] /= vv;
}
for(int j = i + 1; j < width(); j++) {
T a = B[j][i];
for(int k = 0; k < width(); k++) {
B[j][k] -= B[i][k] * a;
}
}
}
return (ret);
}
};
using mint = modint;
void solve(){
LL(p,q,r,k);
p%=10, q %= 10, r %= 10;
mint::set_mod(10);
Matrix<mint> vec(3,1);
vec[0][0] = r, vec[1][0] = q, vec[2][0] = p;
Matrix<mint> mat(3,3);
mat[0][0] = 1,mat[0][1] = 1,mat[0][2] = 1;
mat[1][0] = 1, mat[2][1] = 1;
mat ^= (k-3);
vec = mat * vec;
print(vec[0][0]);
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
cout << setprecision(20);
int codeforces = 1;
//cin >> codeforces;
while(codeforces--){
solve();
}
return 0;
}
tomo0608