B. Little Artem and Grasshopper
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him.

The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip.

Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers di (1 ≤ di ≤ 109) — the length of the jump from the i-th cell.

Output

Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes).

Examples
Input
2
><
1 2
Output
FINITE
Input
3
>><
2 1 1
Output
INFINITE
Note

In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip.

Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite.

题意:有n个区域 每个区域给一个固定跳跃方向‘>’代表向右 和 ‘<’代表向左 接下来的一行代表这个从这个区域能跳跃多远

若能一直跳跃输出INFINITE 否则输出FINITE

题解:存储每个位置的跳跃后的状态 暴力模拟过程

标记 若在某一个位置重复出现 则说明能够一直跳跃输出INFINITE 若跳出1~n的范围则输出FINITE

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#define ll __int64
#define pi acos(-1.0)
#define mod 1
#define maxn 10000
using namespace std;
int n;
map<int,char> mp;
map<int,int> to;
map<int,int> mpp;
int exm;
int main()
{
mp.clear();
mpp.clear();
to.clear();
scanf("%d",&n);
getchar();
for(int i=;i<=n;i++)
scanf("%c",&mp[i]);
for(int i=;i<=n;i++)
{
scanf("%d",&exm);
if(mp[i]=='>')
to[i]=i+exm;
else
to[i]=i-exm;
}
exm=;
int flag=;
while()
{
if(exm>n||exm<)
{
flag=;
break;
}
if(mpp[exm]==)
{
flag=;
break;
}
mpp[exm]=;
exm=to[exm];
}
if(flag)
cout<<"INFINITE"<<endl;
else
cout<<"FINITE"<<endl;
return ;
}

Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) B的更多相关文章

  1. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance

    题目链接: http://codeforces.com/contest/669/problem/D 题意: 给你一个初始序列:1,2,3,...,n. 现在有两种操作: 1.循环左移,循环右移. 2. ...

  2. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C. Little Artem and Random Variable 数学

    C. Little Artem and Random Variable 题目连接: http://www.codeforces.com/contest/668/problem/C Descriptio ...

  3. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) E. Little Artem and Time Machine 树状数组

    E. Little Artem and Time Machine 题目连接: http://www.codeforces.com/contest/669/problem/E Description L ...

  4. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance 模拟

    D. Little Artem and Dance 题目连接: http://www.codeforces.com/contest/669/problem/D Description Little A ...

  5. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C. Little Artem and Matrix 模拟

    C. Little Artem and Matrix 题目连接: http://www.codeforces.com/contest/669/problem/C Description Little ...

  6. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) B. Little Artem and Grasshopper 模拟题

    B. Little Artem and Grasshopper 题目连接: http://www.codeforces.com/contest/669/problem/B Description Li ...

  7. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A. Little Artem and Presents 水题

    A. Little Artem and Presents 题目连接: http://www.codeforces.com/contest/669/problem/A Description Littl ...

  8. Codeforces Round #348(VK Cup 2016 - Round 2)

    A - Little Artem and Presents (div2) 1 2 1 2这样加就可以了 #include <bits/stdc++.h> typedef long long ...

  9. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D

    D. Little Artem and Dance time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  10. Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) C

    C. Little Artem and Matrix time limit per test 2 seconds memory limit per test 256 megabytes input s ...

随机推荐

  1. 3D Food Printing【3D食物打印】

    3D Food Printing There's new frontier in 3D printing that's begining to come into focus: food. 3D打印的 ...

  2. POJ3687 反向拓扑排序

    Labeling Balls Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16032   Accepted: 4713 D ...

  3. python2.7练习小例子(五)

        5):题目:输入三个整数x,y,z,请把这三个数由小到大输出.     程序分析:我们想办法把最小的数放到x上,先将x与y进行比较,如果x>y则将x与y的值进行交换,然后再用x与z进行比 ...

  4. 在WPF中自定义控件(3) CustomControl (上)

    原文:在WPF中自定义控件(3) CustomControl (上) 在WPF中自定义控件(3) CustomControl (上)                              周银辉 ...

  5. Python全栈面试题

    Mr.Seven   博客园 首页 新随笔 联系 订阅 管理 随笔-132  文章-153  评论-516  不吹不擂,你想要的Python面试都在这里了[315+道题]   写在前面 近日恰逢学生毕 ...

  6. 记一次艰难的CTP调试

    一个atmel,mxt540e的CTP触摸屏. 中断配置为下降沿,输入上拉. 总是只能触发一次中断,中断脚就一直低电平,无法拉高.这只是表面现象   不停找底层I2C驱动,改代码,没用.要靠波形来说话 ...

  7. Eclipse+APKTool动态调试APK

    1. 所需工具 Eclipse. Apktool v2.0.6. 安卓SDK工具. 2. 重编译APK apktool d -d -o test test.apk 此时当前test目录下就是apkto ...

  8. 【多校联合】(HDU6043)KazaQ's Socks

    [多校联合](HDU6043)KazaQ's Socks 一条纯粹的水题,记录下只是因为自己错的太多而已. 原因在于对数据的细节的把握不佳. 原题 KazaQ's Socks Time Limit: ...

  9. 解决灰色shader与mask冲突的方案

    Shader "Custom/Opaque" { Properties { [PerRendererData] _MainTex ("Sprite Texture&quo ...

  10. CSS3 : transform 与 transform-origin 属性可以使元素样式发生转变

    CSS3 : transform 用于元素样式的转变,比如使元素发生位移.角度变化.拉伸缩小.按指定角度歪斜 transform结合transition可实现各类动画效果 transform : tr ...