結果

問題 No.1709 Indistinguishable by MEX
ユーザー Learner AditLearner Adit
提出日時 2022-07-05 01:55:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,909 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 199,244 KB
実行使用メモリ 20,412 KB
最終ジャッジ日時 2023-08-21 12:19:34
合計ジャッジ時間 5,921 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,456 KB
testcase_01 AC 4 ms
4,456 KB
testcase_02 AC 4 ms
4,444 KB
testcase_03 AC 3 ms
4,544 KB
testcase_04 AC 4 ms
4,524 KB
testcase_05 AC 4 ms
4,660 KB
testcase_06 AC 3 ms
4,588 KB
testcase_07 AC 3 ms
4,444 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 153 ms
20,240 KB
testcase_24 AC 152 ms
20,248 KB
testcase_25 AC 151 ms
20,196 KB
testcase_26 AC 3 ms
4,604 KB
testcase_27 AC 75 ms
13,412 KB
testcase_28 AC 69 ms
12,540 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void solve(long long int)’ 内:
main.cpp:81:19: 警告: ‘r’ may be used uninitialized [-Wmaybe-uninitialized]
   81 |     for(ll i=n-2;i>r;i--){
      |                  ~^~
main.cpp:64:10: 備考: ‘r’ はここで定義されています
   64 |     ll l,r;
      |          ^
main.cpp:12:35: 警告: ‘l’ may be used uninitialized [-Wmaybe-uninitialized]
   12 | #define fr(x,s,e) for(ll x = s; x < e; ++x)
      |                                   ^
main.cpp:64:8: 備考: ‘l’ はここで定義されています
   64 |     ll l,r;
      |        ^

ソースコード

diff #

/*
            **********************
            **********************
            ***   ADIT SHAH    ***
            ***   DA-IICT      ***
            ***   adit19shah   ***
            **********************
            **********************
*/
#include<bits/stdc++.h>
using namespace std;
#define fr(x,s,e) for(ll x = s; x < e; ++x)
#define ll long long int
#define ld long double
#define imx 1e18
#define imn -1e18
#define pb push_back
#define pll pair<ll,ll>
#define vl vector<ll>
#define ff first
#define ss second
#define bl bool
#define tr true
#define fl false
#define all(v) v.begin(),v.end()
#define eps 1e-9;   //Epsilon value below which approximate floating type number as 0
//#define mod1 1000000007
#define mod1 998244353
#define jadap ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
//For implementing policy based Data Structure, ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
void yno(bool ok)
{
    if(ok)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
vl fact(200001);
void pre(){
    fact[0]=1,fact[1]=1;
    fr(i,2,200001){
        fact[i]=(fact[i-1]*i)%mod1;
        fact[i]%=mod1;
    }
}
void solve(ll z){
    ll n; cin>>n;
    vl v(n);
    fr(i,0,n) cin>>v[i];
    if(n==1){
        cout<<1<<"\n";
        return;
    }
    vl p(n),s(n);
    ordered_set st;
    fr(i,0,n) st.insert(i);
    p[0]=v[0],s[n-1]=v[n-1];
    fr(i,1,n) p[i]=min(v[i],p[i-1]);
    for(ll i=n-2;i>=0;i--) s[i]=min(v[i],s[i+1]);
    ll l,r;
    fr(i,0,n) if(!p[i]) {l=i;break;}
    for(ll i=n-1;i>=0;i--) if(!s[i]) {r=i;break;}
    vl u(n);
    st.erase(v[0]);
    st.erase(v[n-1]);
    st.erase(0);
    fr(i,1,l){
        if(p[i]==p[i-1]){
            ll a=0;
            while(p[i]==p[i-1]) i++,a++;
            u[p[i-1]]=a;
            i--;
        }
        else
            st.erase(v[i]);
    }
    for(ll i=n-2;i>r;i--){
        if(s[i]==s[i+1]){
            ll a=0;
            while(s[i]==s[i+1]) i--,a++;
            u[s[i+1]]=a;
            i++;
        }
        else
            st.erase(v[i]);
    }
    /*fr(i,0,n) cout<<u[i]<<" ";
    cout<<"\n";
    for(auto x:st) cout<<x<<" ";
    cout<<"\n";*/
    ll ans=1;
    for(ll i=n-1;i>=0;i--){
        if(u[i]){
            ll op=(st.size()-st.order_of_key(i));
            ans*=(fact[op]/fact[op-u[i]]);
            ans%=mod1;
            ll zz=u[i];
            while(zz){
                st.erase(prev(st.end()));
                zz--;
            }
        }
    }
    cout<<ans<<"\n";
}
int main()
{
	/*
    #ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
    #endif // ONLINE_JUDGE
    */
    jadap;
    int T=1;
    //cin>>T;
    pre();
    fr(z,0,T){
        solve(z);
    }
    return 0;
}
0