結果
| 問題 | 
                            No.1859 ><<<
                             | 
                    
| ユーザー | 
                             | 
                    
| 提出日時 | 2025-09-11 18:08:07 | 
| 言語 | C++23  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 113 ms / 2,000 ms | 
| コード長 | 1,286 bytes | 
| コンパイル時間 | 7,803 ms | 
| コンパイル使用メモリ | 262,952 KB | 
| 実行使用メモリ | 12,948 KB | 
| 最終ジャッジ日時 | 2025-09-11 18:08:22 | 
| 合計ジャッジ時間 | 11,833 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 41 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); ++i)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define fore(i, a) for(auto &i:a)
using ll = long long;
#define DEBUG(x) cerr << #x << ": "; for (auto _ : x) cerr << _ << " "; cerr << endl;
//ref -> https://qiita.com/t_fuki/items/e682238dda6ad832ce05
//check -> https://judge.yosupo.jp/problem/zalgorithm
vector<int> z_algorithm(string s){
	vector<int> z(s.size(), 0);
	z[0] = s.size();
	int l=0,r=0;
	repi(i, 1, s.size()){
		if(z[i-l] < r-i){
			z[i] = z[i-l];
		}
		else{
			r = max(r, i);
			while(r < s.size() && s[r] == s[r-i])r++;
			z[i] = r-i;
			l = i;
		}
	}
	return z;
}
int main() {
	ll n; cin >> n;
	vector<ll> a(n); rep(i, n)cin >> a[i];
	string s; cin >> s;
	string t(n, '*');
	rep(i, n){
		if(a[i] > a[(i+1)%n])t[i] = '>';
		else t[i] = '<';
	}
	string st = s+'&'+t+'*';
	string ts = t+'&'+s;
	auto z1 = z_algorithm(st);
	auto z2 = z_algorithm(ts);
  rep(i, n){
		if(i == 0){
			if(z1[n] == n-1){
				cout << i << endl;
				return 0;
			}
		}
		else{
			if(z1[n+i]==n-i && (z2[2*n-i+1]==i-1)){
			  cout << i << endl;
			  return 0;
		  }
		}
	}
	cout << -1 << endl;
	
}