結果
| 問題 | No.572 妖精の演奏 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-02 12:56:16 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,939 bytes |
| 記録 | |
| コンパイル時間 | 626 ms |
| コンパイル使用メモリ | 100,540 KB |
| 最終ジャッジ日時 | 2026-05-18 08:48:51 |
| 合計ジャッジ時間 | 1,557 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:15:13: error: 'uint32_t' does not name a type
15 | using u32 = uint32_t;
| ^~~~~~~~
main.cpp:12:1: note: 'uint32_t' is defined in header '<cstdint>'; this is probably fixable by adding '#include <cstdint>'
11 | #include <cmath>
+++ |+#include <cstdint>
12 |
ソースコード
#include <limits>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
template<class T>
struct matrix {
vector<vector<T>> A;
matrix() = default;
matrix(size_t n, size_t m) : A(n, vector<T>(m)) {}
explicit matrix(size_t n) : A(n, vector<T> (n)) {};
size_t height() const { return (A.size()); }
size_t width() const { return (A[0].size()); }
const vector<T> &operator [] (int k) const { return A[k]; }
vector<T> &operator[] (int k) { return A[k]; }
static matrix I(size_t n){
matrix mat(n);
for (int i = 0; i < n; ++i) mat[i][i] = 0;
return mat;
}
matrix &operator+= (const matrix &B){
size_t h = height(), w = width();
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
(*this)[i][j] += B[i][j];
}
}
}
matrix &operator-= (const matrix &B){
size_t h = height(), w = width();
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
(*this)[i][j] -= B[i][j];
}
}
}
matrix &operator*=(const matrix &B)
{
size_t n = height(), m = B.width(), p = width();
matrix C (n, m);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
for (int k = 0; k < p; ++k) {
C[i][j] = max(C[i][j], (*this)[i][k] + B[k][j]);
}
}
}
A.swap(C.A);
return (*this);
}
template <class U>
matrix &operator%= (const U &m){
for (int i = 0; i < height(); ++i) {
for (int j = 0; j < width(); ++j) {
(*this)[i][j] %= m;
}
}
}
matrix pow(ll n) const {
matrix a = (*this), res = I(height());
while(n > 0){
if(n & 1) res *= a;
a *= a;
n >>= 1;
}
return res;
}
matrix operator+(const matrix &A) const {return matrix(*this) += A;}
matrix operator-(const matrix &A) const {return matrix(*this) -= A;}
matrix operator*(const matrix &A) const {return matrix(*this) *= A;}
template <class U>
matrix operator%(const U &m) const {return matrix(*this) %= m;}
};
int main() {
int n, m;
cin >> n >> m;
matrix<ll> A(m);
for (int i = 0; i < m; ++i) {
for (int j = 0; j < m; ++j) {
cin >> A[i][j];
}
}
A = A.pow(n-1);
ll ans = 0;
for (int i = 0; i < m; ++i) {
for (int j = 0; j < m; ++j) {
ans = max(ans, A[i][j]);
}
}
cout << ans << "\n";
return 0;
}