結果

問題 No.1859 ><<<
ユーザー 👑 emthrmemthrm
提出日時 2022-02-26 22:56:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 2,877 bytes
コンパイル時間 2,473 ms
コンパイル使用メモリ 205,200 KB
実行使用メモリ 20,064 KB
最終ジャッジ日時 2023-09-18 03:13:27
合計ジャッジ時間 8,709 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 76 ms
20,064 KB
testcase_05 AC 76 ms
20,024 KB
testcase_06 AC 75 ms
19,996 KB
testcase_07 AC 76 ms
20,060 KB
testcase_08 AC 77 ms
20,048 KB
testcase_09 AC 74 ms
20,020 KB
testcase_10 AC 14 ms
5,868 KB
testcase_11 AC 47 ms
12,796 KB
testcase_12 AC 40 ms
11,888 KB
testcase_13 AC 25 ms
8,244 KB
testcase_14 AC 48 ms
13,732 KB
testcase_15 AC 66 ms
17,548 KB
testcase_16 AC 71 ms
18,688 KB
testcase_17 AC 54 ms
15,080 KB
testcase_18 AC 71 ms
18,364 KB
testcase_19 AC 53 ms
14,488 KB
testcase_20 AC 65 ms
17,580 KB
testcase_21 AC 73 ms
19,768 KB
testcase_22 AC 69 ms
18,852 KB
testcase_23 AC 63 ms
17,280 KB
testcase_24 AC 70 ms
19,196 KB
testcase_25 AC 72 ms
18,688 KB
testcase_26 AC 67 ms
17,860 KB
testcase_27 AC 73 ms
18,744 KB
testcase_28 AC 69 ms
18,384 KB
testcase_29 AC 70 ms
18,072 KB
testcase_30 AC 66 ms
17,312 KB
testcase_31 AC 67 ms
17,304 KB
testcase_32 AC 75 ms
19,712 KB
testcase_33 AC 66 ms
17,568 KB
testcase_34 AC 68 ms
18,420 KB
testcase_35 AC 76 ms
19,708 KB
testcase_36 AC 75 ms
19,700 KB
testcase_37 AC 68 ms
17,828 KB
testcase_38 AC 78 ms
19,988 KB
testcase_39 AC 76 ms
19,856 KB
testcase_40 AC 71 ms
19,144 KB
testcase_41 AC 72 ms
19,700 KB
testcase_42 AC 66 ms
17,568 KB
testcase_43 AC 71 ms
19,096 KB
testcase_44 AC 70 ms
18,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

template <typename T = std::string>
struct RollingHash {
  T s;

  explicit RollingHash(const T& s, const int base = 10007,
                       const int mod = 1000000007)
      : base(base), mod(mod), hash({0}), power({1}) {
    const int n = s.size();
    this->s.reserve(n);
    hash.reserve(n + 1);
    power.reserve(n + 1);
    add(s);
  }

  long long get(const int left, const int right) const {
    const long long res =
        hash[right] - hash[left] * power[right - left] % mod;
    return res < 0 ? res + mod : res;
  }

  void add(const T& t) {
    for (const auto c : t) {
      s.push_back(c);
      const int hash_nxt = (hash.back() * base % mod + c) % mod;
      hash.emplace_back(hash_nxt);
      const int power_nxt = power.back() * base % mod;
      power.emplace_back(power_nxt);
    }
  }

  int longest_common_prefix(const int i, const int j) const {
    const int n = s.size();
    int lb = 0, ub = n + 1 - std::max(i, j);
    while (ub - lb > 1) {
      const int mid = (lb + ub) >> 1;
      (get(i, i + mid) == get(j, j + mid) ? lb : ub) = mid;
    }
    return lb;
  }

  template <typename U>
  int longest_common_prefix(const RollingHash<U>& t,
                            const int i, const int j) const {
    int lb = 0;
    int ub = std::min(static_cast<int>(s.size()) - i,
                      static_cast<int>(t.str.size()) - j)
             + 1;
    while (ub - lb > 1) {
      const int mid = (lb + ub) >> 1;
      (get(i, i + mid) == t.get(j, j + mid) ? lb : ub) = mid;
    }
    return lb;
  }

 private:
  const int base, mod;
  std::vector<long long> hash, power;
};

int main() {
  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  string t = "";
  FOR(i, 1, n * 2) t += (a[(i - 1) % n] < a[i % n] ? '<' : '>');
  string s; cin >> s;
  RollingHash rh_t(t), rh_s(s);
  REP(i, n) {
    if (rh_t.get(i, i + n - 1) == rh_s.get(0, n - 1)) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << "-1\n";
  return 0;
}
0