提出 #73540093
ソースコード 拡げる
//#pragma GCC optimize("O3", "unroll-loops", "inline-functions")
#include <bits/stdc++.h>
using namespace std;
#define all(X) X.begin(),X.end()
#define rall(X) X.rbegin(),X.rend()
#define ll long long
template<typename T>
static inline void chmax(T &x , T v){x = max(x , v);}
template<typename T>
static inline void chmin(T &x , T v){x = min(x , v);}
const ll mod = 998244353;
ll mult(ll a , ll b){
a %= mod;b %= mod;
return (a * b)%mod;
}
ll add(ll a , ll b){
a %= mod;b %= mod;
return (a + b)%mod;
}
static inline ll binpow_m(ll a, ll p){
ll res = 1;
for(ll i = 1;i <= p;i <<= 1){
if(i & p)res = mult(res , a);
a = mult(a , a);
}
return res;
}
static inline void fix(ll &val){
val %= mod;
if(val < 0)val += mod;
}
const ll INF = 2e18;
const int OL = 2e5 + 5;
int dir1[] = {0 , 1 , 0 , -1};
int dir2[] = {1 , 0 , -1 , 0};
//################################################
#define int ll
void solve(){
int n;
cin>>n;
vector<ll>arr(n + 3);
auto dp = arr;
auto mem = dp;
for(int i = 1;i <= n;i++){
cin>>arr[i];
}
deque<int>idxs[n + 1] ;
dp[0] = 1;
ll acu = 0;
for(int i = 1;i <= n;i++){
dp[i] = 1;
idxs[arr[i]].push_back(i);
if(idxs[arr[i]].size() == arr[i]){
mem[arr[i]] = dp[idxs[arr[i]].front() - 1];
(acu += mem[arr[i]]) %= mod;
}
else if(idxs[arr[i]].size() > arr[i]){
(acu -= mem[arr[i]]) %= mod;
idxs[arr[i]].pop_front();
int z = idxs[arr[i]].front();
mem[arr[i]] = dp[z - 1];
(acu += mem[arr[i]]) %= mod;
//if(acu < 0)acu += mod;
}
ll cont = (acu - mem[arr[i + 1]]) % mod;
(dp[i] = cont + 1) %= mod;
if(dp[i] < 0)dp[i] += mod;
}
dp[n] -= 1;
dp[n] %= mod;
if(dp[n] < 0)dp[n] += mod;
cout<<dp[n]<<'\n';
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
//mock();
int t = 1;
//cin >> t;
while (t--)
{
solve();
}
return 0;
}
提出情報
コンパイルエラー
./Main.cpp: In function 'void solve()':
./Main.cpp:67:40: warning: comparison of integer expressions of different signedness: 'std::deque<long long int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} [-Wsign-compare]
67 | if(idxs[arr[i]].size() == arr[i]){
./Main.cpp:71:45: warning: comparison of integer expressions of different signedness: 'std::deque<long long int>::size_type' {aka 'long unsigned int'} and '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type' {aka 'long long int'} [-Wsign-compare]
71 | else if(idxs[arr[i]].size() > arr[i]){
ジャッジ結果
| セット名 |
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 |
1 ms |
3540 KiB |
| 00-sample-02.txt |
AC |
1 ms |
3528 KiB |
| 00-sample-03.txt |
AC |
1 ms |
3504 KiB |
| 01-01.txt |
AC |
1 ms |
3604 KiB |
| 01-02.txt |
AC |
1 ms |
3416 KiB |
| 01-03.txt |
AC |
1 ms |
3528 KiB |
| 01-04.txt |
AC |
1 ms |
3528 KiB |
| 01-05.txt |
AC |
172 ms |
351176 KiB |
| 01-06.txt |
AC |
138 ms |
292680 KiB |
| 01-07.txt |
AC |
193 ms |
353456 KiB |
| 01-08.txt |
AC |
190 ms |
351100 KiB |
| 01-09.txt |
AC |
189 ms |
354872 KiB |
| 01-10.txt |
AC |
188 ms |
353096 KiB |
| 01-11.txt |
AC |
171 ms |
355144 KiB |
| 01-12.txt |
AC |
167 ms |
317496 KiB |
| 01-13.txt |
AC |
98 ms |
186612 KiB |
| 01-14.txt |
AC |
156 ms |
292220 KiB |
| 01-15.txt |
AC |
173 ms |
320940 KiB |
| 01-16.txt |
AC |
156 ms |
289580 KiB |