結果

問題 No.1859 ><<<
ユーザー ShirotsumeShirotsume
提出日時 2022-01-04 02:16:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 1,951 bytes
コンパイル時間 2,135 ms
コンパイル使用メモリ 201,480 KB
実行使用メモリ 6,048 KB
最終ジャッジ日時 2023-09-17 22:55:24
合計ジャッジ時間 5,894 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 40 ms
5,824 KB
testcase_05 AC 41 ms
5,812 KB
testcase_06 AC 40 ms
5,748 KB
testcase_07 AC 40 ms
5,800 KB
testcase_08 AC 41 ms
5,760 KB
testcase_09 AC 41 ms
5,840 KB
testcase_10 AC 8 ms
4,376 KB
testcase_11 AC 27 ms
4,776 KB
testcase_12 AC 23 ms
4,584 KB
testcase_13 AC 14 ms
4,380 KB
testcase_14 AC 24 ms
4,844 KB
testcase_15 AC 34 ms
5,420 KB
testcase_16 AC 42 ms
5,840 KB
testcase_17 AC 28 ms
4,996 KB
testcase_18 AC 40 ms
5,712 KB
testcase_19 AC 28 ms
4,960 KB
testcase_20 AC 32 ms
5,444 KB
testcase_21 AC 36 ms
5,920 KB
testcase_22 AC 31 ms
5,868 KB
testcase_23 AC 32 ms
5,380 KB
testcase_24 AC 33 ms
6,048 KB
testcase_25 AC 41 ms
5,828 KB
testcase_26 AC 34 ms
5,468 KB
testcase_27 AC 44 ms
5,784 KB
testcase_28 AC 36 ms
5,712 KB
testcase_29 AC 41 ms
5,568 KB
testcase_30 AC 38 ms
5,428 KB
testcase_31 AC 36 ms
5,372 KB
testcase_32 AC 44 ms
5,904 KB
testcase_33 AC 37 ms
5,612 KB
testcase_34 AC 35 ms
5,556 KB
testcase_35 AC 43 ms
5,920 KB
testcase_36 AC 43 ms
5,960 KB
testcase_37 AC 40 ms
5,648 KB
testcase_38 AC 48 ms
5,972 KB
testcase_39 AC 44 ms
5,972 KB
testcase_40 AC 35 ms
5,716 KB
testcase_41 AC 33 ms
5,976 KB
testcase_42 AC 34 ms
5,608 KB
testcase_43 AC 36 ms
5,828 KB
testcase_44 AC 37 ms
5,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=1167167167167167167;
const int INF=2100000000;
const ll mod=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}


const int MAX_N=300000;

//  rainy ~ 雨に打たれて ~
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int N;
    cin>>N;
    assert(2<=N&&N<=MAX_N);
    vector<int> p(N),q(N);
	rep(i,N){
        int a;
        cin>>a;
        a--;
        assert(0<=a&&a<N);
        assert(q[a]==0);
        q[a]++;
        p[i]=a;
    }
    string S;
    cin>>S;
    assert(S.size()==(N-1));
    ll ans=0;
    ll base=1;
    ll tmp=0;
    rep(i,N-1){
        assert(S[i]=='>'||S[i]=='<');
        if(S[i]=='<') ans+=base;
        base*=2ll;
        base%=mod;
    }
    base=1;
    rep(i,N-1){
        if(p[i]<p[i+1]) tmp+=base;
        base*=2ll;
        base%=mod;
    }
    ans%=mod;
    tmp%=mod;
    rep(i,N){
        if(ans==tmp){
            cout<<i<<"\n";
            return 0;
        }
        if(p[(i+N-1)%N]<p[i%N]) tmp+=base;
        if(p[i]<p[(i+1)%N]) tmp--;
        if(tmp%2) tmp=(tmp+mod)/2;
        else tmp/=2;
        tmp=(tmp%mod+mod)%mod;
    }
    cout<<"-1\n";
}


0