fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. typedef pair< int, int > pii;
  6. typedef pair< ll, ll > pll;
  7.  
  8. long d[100005];
  9.  
  10. int main(){
  11.  
  12. int n;
  13. char s[100005];
  14. long pos= 0;
  15. bool flag1= true;
  16. bool infinite= false;
  17. vector< long > position;
  18.  
  19. scanf( "%d", &n );
  20. scanf( "%s", &s );
  21.  
  22. for( int i= 0; i< n; ++i )
  23. scanf( "%ld", &d[i] );
  24.  
  25. int i= 0;
  26. position.push_back( pos );
  27.  
  28. //cout << pos+1 << ' ';
  29.  
  30. if( s[pos]== '<' ){
  31. cout << "FINITE\n";
  32. return 0;
  33. }
  34.  
  35. //cout << pos+1 << ' ';
  36.  
  37. while( true ){
  38.  
  39. if( s[pos]== '<' ){
  40. pos-= d[pos];
  41. }else{
  42. pos+= d[pos];
  43. }
  44.  
  45. position.push_back( pos );
  46. ++i;
  47.  
  48. //cout << pos+1 << ' ';
  49.  
  50. if( pos < 0 || pos >= n )
  51. break;
  52.  
  53. if( i >= 3 ){
  54.  
  55. if( position[i]== position[i-2] && position[i-1]== position[i-3] ){
  56. infinite= true;
  57. break;
  58. }
  59. }
  60.  
  61. }
  62.  
  63. if( infinite ){
  64. cout << "INFINITE\n";
  65. }else {
  66. cout << "FINITE\n";
  67. }
  68.  
  69.  
  70. }
Runtime error #stdin #stdout #stderr 2s 529408KB
stdin
7
>>><><<
1 1 2 2 2 2 1
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc