ural 2020 Traffic Jam in Flower Town

2020. Traffic Jam in Flower Town

Time limit: 1.0 second
Memory limit: 64 MB

Having returned from Sun City, Dunno told all his friends that every shorty may have a personal automobile. Immediately after that so many citizens took a fancy of becoming road-users, that Bendum and Twistum had to make a mass production of cars on soda water with syrup. Now traffic jams from several cars occasionally appear on the crossing of Bell-flower Street and Daisy Street.

Bell-flower Street goes from the South to the North and has two driving paths. It has the right driving, i. e. automobiles move from the South to the North on the Eastern path and from the North to the South on the Western path. Daisy Street is single-pathed, and it is perpendicular to Bell-flower Street. There is one-way movement on it, but its driving direction is organized in such a way that automobiles drive away from the crossroad in two opposite directions (see the picture).

Yesterday on his way home Dunno saw cars standing in a traffic jam on Bell-flower Street from different sides of the crossing with Daisy Street. Some of the drivers wanted to go forward, some wanted to turn right or left. An automobile can pass the crossing in one second, but if the driver is turning left, he first have to let pass all oncoming vehicles, going forward and to the right. How many seconds did it take all the cars to pass the crossing, providing that no other cars drove up to the crossing?

Input

The first line contains the sequence of symbols “F”, “L” and “R”, describing directions in which drivers who arrived to the crossing from the South wanted to go. “F” stands for those drivers who were going forward, “L” is for those who were turning left, and “R” is for those who were turning right. Automobiles are listed in the order from the closest to the crossing to the farthest one. The second line contains the description of the cars, arrived to the crossing from the North, in the same form. Both sequences have length from 1 to 1 000.

Output

Output time in seconds, which took all the cars to pass the crossing.

Samples

input output
RLF
FF
4
L
L
1

Notes

In the first example we number the cars from 1 to 5 in the order described in the input data. Then in the first second the crossing was passed by the first and the fourth cars because they didn’t cause an obstruction to each other. Then the second car was turning left and had to let the fifth car pass. As a result, at each of the following three seconds only one car passed the crossing, and their order was as follows: the fifth one, the second one and the third one.

In the second example the cars didn’t cause any obstruction to each other and turned simultaneously.

Problem Author: Denis Dublennykh (prepared by Nick Burlakov)
Problem Source: NEERC 2014, Eastern subregional contest

Tags: none  (hide tags for unsolved problems)

Difficulty: 122    Printable version    Submit solution    Discussion (3)
All submissions (2839)    All accepted submissions (1210)    Solutions rating (901)

时间: 2024-08-03 15:35:40

ural 2020 Traffic Jam in Flower Town的相关文章

URAL - 1785,1293,1877,1409,1820,1787,1264,2012

开始水URAL,今天先来几个.. 1785. Lost in Localization Time limit: 1.0 second Memory limit: 64 MB The Lavin Interactive Company, which has developed the turn-based strategy Losers-V, is constantly extending its target market by localizing the game to as many la

UVALive 2664 One-way traffic

One-way traffic Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALive. Original ID: 266464-bit integer IO format: %lld      Java class name: Main In a certain town there are n intersections connected by two- and one-way str

URAL 1787 Turn for MEGA (贪心 + 模拟)

Turn for MEGA Time limit: 1.0 second Memory limit: 64 MB A traffic light at the turn for the "MEGA" shopping center from the Novomoskovskiy highway works in such a way that k cars are able to take a turn in one minute. At weekends all the reside

LightOJ 1291 Real Life Traffic

Real Life Traffic Time Limit: 2000ms Memory Limit: 32768KB This problem will be judged on LightOJ. Original ID: 129164-bit integer IO format: %lld      Java class name: Main Dhaka city is full of traffic jam and when it rains, some of the roads becom

<老友记>学习笔记

这是六个人的故事,从不服输而又有强烈控制欲的monica,未经世事的千金大小姐rachel,正直又专情的ross,幽默风趣的chandle,古怪迷人的phoebe,花心天真的joey——六个好友之间的情路坎坷,事业成败和生活中的喜怒哀乐,无时无刻不牵动着彼此的心,而正是正平凡的点点滴滴,却成为最令人感动与留恋的东西. 人物:1.瑞秋•格林(RACHEL GREENE)由珍妮佛•安妮斯顿(Jennifer Aniston)扮演 瑞秋是莫妮卡的高中同学,在与牙医未婚夫的婚礼上脱逃至莫妮卡处. 2.罗

(转) Artificial intelligence, revealed

Artificial intelligence, revealed Yann LeCunJoaquin Qui?onero Candela It's 8:00 am on a Tuesday morning. You've awoken, scanned the headlines on your phone, responded to an online post, ordered a holiday sweater for your mom, locked up the house, and

英语新闻常用词汇与短语

英语新闻常用词汇与短语 经济篇 accumulated deficit 累计赤字 active trade balance 贸易顺差 adverse trade balance 贸易逆差 aid 援助 allocation of funds 资金分配 allotment 拨款 allowance/grant/subsidy 补贴,补助金,津贴 amortization 摊销,摊还,分期偿付 annuity 年金 article 物品,商品 assigned 过户 autarchy 闭关自守 av

智能汽车无人驾驶资料调研(一)

1.提出无人驾驶演进的五个维度:消费者接受度.技术整合度.生态体系.立法.基础设施投资: 2.无人驾驶的关键技术:环境感知技术.定位导航技术.路径规划技术和决策控制技术.(分类有待商榷,比如V2X通信技术等未包括) 给出SAE给的最新L0-L5的无人驾驶定义: 自动驾驶分级 名称(SAE) 定义(SAE) NHTSA SAE 0 0 无自动化 无自动驾驶,由人类驾驶员全权操控汽车,可以得到警告或干预系统的辅助: 1 1 驾驶支援 通过驾驶环境对方向盘和加减速中的一项操作提供驾驶支持,其他的驾驶动

20150713 DAY2 first

WORD LIST freshman, first-year studentoverseas, overseas studentsdiploma,certificate,credentialnotebook,handbookForbesCambridgereviewdictationmicrophonenoticeboard,bulletin boardtechnical,technical vocabulary=jargon=term,technical institutionimportan