結果

問題 No.1859 ><<<
ユーザー Nzt3Nzt3
提出日時 2022-03-16 00:18:10
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,160 bytes
コンパイル時間 3,409 ms
コンパイル使用メモリ 171,244 KB
実行使用メモリ 7,224 KB
最終ジャッジ日時 2023-10-23 23:43:56
合計ジャッジ時間 7,420 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 74 ms
7,184 KB
testcase_05 AC 74 ms
7,184 KB
testcase_06 AC 73 ms
7,184 KB
testcase_07 AC 74 ms
7,184 KB
testcase_08 AC 75 ms
7,184 KB
testcase_09 AC 75 ms
7,184 KB
testcase_10 AC 14 ms
4,368 KB
testcase_11 AC 48 ms
5,596 KB
testcase_12 AC 40 ms
5,248 KB
testcase_13 AC 23 ms
4,524 KB
testcase_14 AC 40 ms
5,652 KB
testcase_15 AC 58 ms
6,492 KB
testcase_16 AC 74 ms
6,916 KB
testcase_17 AC 46 ms
5,988 KB
testcase_18 AC 71 ms
6,816 KB
testcase_19 AC 48 ms
5,956 KB
testcase_20 AC 60 ms
6,504 KB
testcase_21 AC 68 ms
6,944 KB
testcase_22 AC 58 ms
6,908 KB
testcase_23 AC 59 ms
6,468 KB
testcase_24 AC 62 ms
6,964 KB
testcase_25 AC 74 ms
6,896 KB
testcase_26 AC 59 ms
6,780 KB
testcase_27 AC 76 ms
6,868 KB
testcase_28 AC 61 ms
6,848 KB
testcase_29 AC 70 ms
6,788 KB
testcase_30 AC 66 ms
6,460 KB
testcase_31 AC 61 ms
6,452 KB
testcase_32 AC 76 ms
6,952 KB
testcase_33 AC 64 ms
6,552 KB
testcase_34 AC 59 ms
6,800 KB
testcase_35 AC 76 ms
6,964 KB
testcase_36 AC 73 ms
6,968 KB
testcase_37 AC 70 ms
6,576 KB
testcase_38 AC 82 ms
7,224 KB
testcase_39 AC 73 ms
6,980 KB
testcase_40 AC 64 ms
6,864 KB
testcase_41 AC 60 ms
6,980 KB
testcase_42 AC 63 ms
6,556 KB
testcase_43 AC 67 ms
6,884 KB
testcase_44 AC 68 ms
6,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long modpow(long long a,int n,long long mod){
  long long ret=1,t=a;
  for(int i=0;i<31;i++){
    if(n>>i&1)ret=ret*t%mod;
    t=t*t%mod;
  }
  return ret;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin>>N;
  vector<int>A(N);
  for(int &i:A)cin>>i;
  string S;
  cin>>S;
  vector<int>F(N*2+1);
  for(int i=0;i<=N*2;i++){
    F[i]=A[i%N]>A[(i+1)%N];
  }

  const int mod[4]={1000000007,1000000009,998244853,998244353};
  array<long long,4>inori={0ll,0ll,0ll,0ll},awase=inori,modkese;
  for(int i=0;i<4;i++)modkese[i]=modpow(2,N-1,mod[i]);
  for(int i=0;i<N-1;i++){
    for(int j=0;j<4;j++){
      inori[j]=(inori[j]*2+(S[i]=='>'?1:0))%mod[j];
    }
  }
  for(int i=0;i<N-1;i++){
    for(int j=0;j<4;j++){
      awase[j]=(awase[j]*2+F[i])%mod[j];
    }
  }
  for(int i=N-1;i<N*2;i++){
    if(inori==awase){
      cout<<i-N+1<<'\n';
      return 0;
    }
    for(int j=0;j<4;j++){
      awase[j]=(awase[j]*2+F[i])%mod[j];
      if(F[i-N+1])awase[j]=(awase[j]-modkese[j]+mod[j])%mod[j];
    }
  }
  if(inori==awase){
      cout<<N-1<<'\n';
      return 0;
    }
  cout<<"-1\n";
}
0