結果

問題 No.1859 ><<<
ユーザー RaffRaff
提出日時 2022-03-23 10:42:07
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,978 bytes
コンパイル時間 1,472 ms
コンパイル使用メモリ 171,552 KB
実行使用メモリ 14,556 KB
最終ジャッジ日時 2024-04-19 16:06:46
合計ジャッジ時間 4,928 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,820 KB
testcase_03 AC 1 ms
6,820 KB
testcase_04 AC 45 ms
14,544 KB
testcase_05 AC 43 ms
14,540 KB
testcase_06 AC 44 ms
14,556 KB
testcase_07 AC 42 ms
14,516 KB
testcase_08 AC 46 ms
14,468 KB
testcase_09 AC 43 ms
14,448 KB
testcase_10 AC 9 ms
6,944 KB
testcase_11 AC 30 ms
9,860 KB
testcase_12 AC 25 ms
8,944 KB
testcase_13 AC 15 ms
6,948 KB
testcase_14 AC 29 ms
10,256 KB
testcase_15 AC 38 ms
13,084 KB
testcase_16 AC 42 ms
13,532 KB
testcase_17 AC 31 ms
11,080 KB
testcase_18 AC 44 ms
13,636 KB
testcase_19 AC 31 ms
10,752 KB
testcase_20 AC 39 ms
12,972 KB
testcase_21 AC 43 ms
14,260 KB
testcase_22 AC 40 ms
13,956 KB
testcase_23 AC 36 ms
12,840 KB
testcase_24 AC 43 ms
14,068 KB
testcase_25 AC 43 ms
13,500 KB
testcase_26 AC 39 ms
13,100 KB
testcase_27 AC 47 ms
13,740 KB
testcase_28 AC 42 ms
13,508 KB
testcase_29 AC 42 ms
13,328 KB
testcase_30 AC 40 ms
12,908 KB
testcase_31 AC 39 ms
12,864 KB
testcase_32 AC 46 ms
14,088 KB
testcase_33 AC 40 ms
12,836 KB
testcase_34 AC 41 ms
13,316 KB
testcase_35 AC 45 ms
14,244 KB
testcase_36 AC 47 ms
14,136 KB
testcase_37 AC 41 ms
12,920 KB
testcase_38 AC 46 ms
14,420 KB
testcase_39 AC 43 ms
14,332 KB
testcase_40 AC 42 ms
14,024 KB
testcase_41 AC 44 ms
14,236 KB
testcase_42 AC 37 ms
12,752 KB
testcase_43 AC 40 ms
13,644 KB
testcase_44 AC 42 ms
13,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, x, n) for(int i = (x); i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i >= 0; --i)
#define RREP(i, x, n) for(int i = n - 1; i >= (x); --i)
#define all(x) x.begin(), x.end()
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vvvvi = vector<vvvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using vp = vector<P>;
using vvp = vector<vp>;

template <class T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if(b < a) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T> vector<int> Zalgorithm(vector<T> S) {
    int n = S.size();
    vector<int> arr(n);
    arr[0] = n;
    int i = 1, j = 0;
    while(i < n) {
        while(i + j < n && S[j] == S[i + j]) ++j;
        arr[i] = j;
        if(j == 0) {
            ++i;
            continue;
        }
        int k = 1;
        while(i + k < n && k + arr[k] < j) {
            arr[i + k] = arr[k];
            ++k;
        }
        i += k;
        j -= k;
    }
    return arr;
}

void solve() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    string s;
    cin >> s;

    string t;
    rep(i, 2 * n - 2) t += (a[(i) % n] < a[(i + 1) % n] ? '<' : '>');

    vector<char> u;
    for(char &e : s) u.push_back(e);
    for(char &e : t) u.push_back(e);
    for(char &e : t) u.push_back(e);

    --n;
    auto z = Zalgorithm(u);

    REP(i, n, 3 * n) {
        if(z[i] >= n) {
            cout << i - n << endl;
            return;
        }
    }
    cout << -1 << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    // cin >> t;

    while(t--) solve();

    return 0;
}
0