QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21299. Razze bovine bilanciate

Statistics

Farmer John marca normalmente le mucche con un cerchio, ma il ferro è rotto e usa una parentesi (. Ha due razze, Holstein e Guernsey. Ogni mucca porta il segno, che appare parentesi sinistra o destra secondo dove guarda.

Le $N$ mucche sono in fila in direzioni arbitrarie e formano una stringa di parentesi lunga $N$. FJ nota che leggendo solo Holstein da sinistra a destra nel loro ordine ottiene una stringa bilanciata, come per Guernsey! Per sapere se è raro, conta le assegnazioni delle razze alle $N$ mucche con questa proprietà.

Ci sono varie definizioni di “bilanciata”. La più semplice richiede ugual numero totale di ( e ), e in ogni prefisso almeno tante ( quante ). Per esempio, queste stringhe sono bilanciate:

()
(())
()(()())

queste invece no:

)(
())(
((())))

Input

  • Riga 1: stringa di parentesi lunga $N$ $(1 \le N \le 1000)$.

Output

  • Riga 1: un intero, il numero di assegnazioni affinché Holstein e Guernsey formino ciascuna una sottosequenza bilanciata. Può essere grande: stampa il resto per 2012, cioè modulo 2012. Sono valide assegnazioni di una sola razza.

Esempi

Input 1

(())

Output 1

6

Nota

Le seguenti assegnazioni funzionano:

(())
HHHH
(())
GGGG
(())
HGGH
(())
GHHG
(())
HGHG
(())
GHGH

Autore del problema: Brian Dean, 2012

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.