提出 #73530703
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
ll n;
ll a[500050], dp1[500050], dp2[500050];
vector<ll> v[500050];
int main()
{
cin>>n;
for (ll i=1;i<=n;i++)
{
cin>>a[i];
v[a[i]].push_back(i);
}
dp1[n+1]=1; dp2[n+1]=1;
for (ll i=n;i>=1;i--)
{
ll add=0;
auto idx = lower_bound(v[a[i]].begin(),v[a[i]].end(),i)-v[a[i]].begin();
if (idx+a[i]-1<=v[a[i]].size()-1) add+=dp2[v[a[i]][idx+a[i]-1]+1];
if (idx+a[i]<=v[a[i]].size()-1) add-=dp2[v[a[i]][idx+a[i]]+1];
dp1[i]=(dp1[i+1]+add)%mod;
if (i==1) break;
ll sub=0;
auto idx2 = lower_bound(v[a[i-1]].begin(),v[a[i-1]].end(),i)-v[a[i-1]].begin();
if (idx2+a[i-1]-1<=v[a[i-1]].size()-1) sub=dp2[v[a[i-1]][idx2+a[i-1]-1]+1];
dp2[i]=(dp1[i]-sub)%mod;
}
/*for (ll i=1;i<=n;i++) cout<<dp1[i]<<" ";
cout<<"\n";
for (ll i=1;i<=n;i++) cout<<dp2[i]<<" ";
cout<<"\n";*/
cout<<(dp1[1]-1+mod)%mod;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | G - 221 Subsequence |
| ユーザ | prologue1017 |
| 言語 | C++23 (GCC 15.2.0) |
| 得点 | 600 |
| コード長 | 1065 Byte |
| 結果 | AC |
| 実行時間 | 189 ms |
| メモリ | 37624 KiB |
コンパイルエラー
./Main.cpp: In function 'int main()':
./Main.cpp:23:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | if (idx+a[i]-1<=v[a[i]].size()-1) add+=dp2[v[a[i]][idx+a[i]-1]+1];
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~
./Main.cpp:24:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | if (idx+a[i]<=v[a[i]].size()-1) add-=dp2[v[a[i]][idx+a[i]]+1];
| ~~~~~~~~^~~~~~~~~~~~~~~~~~
./Main.cpp:29:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | if (idx2+a[i-1]-1<=v[a[i-1]].size()-1) sub=dp2[v[a[i-1]][idx2+a[i-1]-1]+1];
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 600 / 600 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt |
| All | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00-sample-01.txt | AC | 3 ms | 3496 KiB |
| 00-sample-02.txt | AC | 3 ms | 3368 KiB |
| 00-sample-03.txt | AC | 3 ms | 3404 KiB |
| 01-01.txt | AC | 3 ms | 3528 KiB |
| 01-02.txt | AC | 3 ms | 3428 KiB |
| 01-03.txt | AC | 3 ms | 3448 KiB |
| 01-04.txt | AC | 3 ms | 3428 KiB |
| 01-05.txt | AC | 111 ms | 19100 KiB |
| 01-06.txt | AC | 91 ms | 16424 KiB |
| 01-07.txt | AC | 110 ms | 22012 KiB |
| 01-08.txt | AC | 189 ms | 37624 KiB |
| 01-09.txt | AC | 107 ms | 20448 KiB |
| 01-10.txt | AC | 99 ms | 20324 KiB |
| 01-11.txt | AC | 161 ms | 19064 KiB |
| 01-12.txt | AC | 98 ms | 19196 KiB |
| 01-13.txt | AC | 68 ms | 16952 KiB |
| 01-14.txt | AC | 108 ms | 17204 KiB |
| 01-15.txt | AC | 115 ms | 18240 KiB |
| 01-16.txt | AC | 101 ms | 17664 KiB |