結果
| 問題 |
No.1378 Flattening
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-16 00:16:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,374 bytes |
| コンパイル時間 | 956 ms |
| コンパイル使用メモリ | 92,420 KB |
| 最終ジャッジ日時 | 2024-11-15 02:28:21 |
| 合計ジャッジ時間 | 1,753 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:36:5: error: 'cin' was not declared in this scope
36 | cin >> n;
| ^~~
main.cpp:2:1: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
1 | #include <atcoder/all>
+++ |+#include <iostream>
2 | using namespace std;
main.cpp:49:5: error: 'cout' was not declared in this scope
49 | cout << dp[n].val() << endl;
| ^~~~
main.cpp:49:5: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
main.cpp:49:28: error: 'endl' was not declared in this scope
49 | cout << dp[n].val() << endl;
| ^~~~
main.cpp:2:1: note: 'std::endl' is defined in header '<ostream>'; did you forget to '#include <ostream>'?
1 | #include <atcoder/all>
+++ |+#include <ostream>
2 | using namespace std;
ソースコード
#include <atcoder/all>
using namespace std;
using mint = atcoder::modint998244353;
template<class T,T (*op)(T, T)> struct SparseTable {
vector<vector<T>> table;
vector<int> lookup;
int LOGV=0, _n;
SparseTable(const vector<T> &v) {
_n=v.size();
while(_n>>LOGV)LOGV++;
table.assign(LOGV,vector<T>(_n));
lookup.resize(_n+1);
for(int i = 0; i < _n; i++) table[0][i] = v[i];
for(int i = 1; i < LOGV; i++) {
for(int j = 0; j + (1 << i) <= _n; j++) {
table[i][j] = op(table[i - 1][j], table[i - 1][j + (1 << (i - 1))]);
}
}
lookup[1]=0;
for(int i = 2; i < lookup.size(); i++) {
lookup[i] = lookup[i >> 1] + 1;
}
}
inline T prod(const int l, const int r){
assert(0 <= l && l < r && r <= _n);
int b = lookup[r - l];
return op(table[b][l],table[b][r - (1<<b)]);
}
};
int op(int l, int r){return min(l, r);}
int main(){
int n;
cin >> n;
vector<int> a(n);
for(auto &&v:a) cin >> v;
SparseTable<int,op> st(a);
vector<mint> dp(n + 1);
dp[0] = 1;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
if(st.prod(min(i, j), max(i, j) + 1) == a[i]){
dp[j + 1] += dp[j];
}
}
}
cout << dp[n].val() << endl;
}