QOJ.ac

QOJ

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

#21074. קוד סודי

Statistics

ל־Farmer John יש הודעה סודית שהוא רוצה להסתיר מפרותיו: מחרוזת באורך לפחות 2 המכילה רק תווים A..Z.

להצפנה FJ מבצע רצף ״פעולות״. פעולה על $S$ קודם מקצרת אותה במחיקת התוו הראשון או האחרון, ואז מחברת את המחרוזת המקורית $S$ בתחילת המחרוזת או בסופה. למשל, פעולה אחת על ABCD יכולה לתת ארבע מחרוזות:

BCDABCD ABCABCD ABCDABC ABCDBCD

בהינתן המחרוזת המוצפנת הסופית, ספרו את מספר הדרכים שבהן FJ יכול היה ליצור אותה באמצעות פעולה אחת או יותר ברצף על מחרוזת מקור כלשהי. פעולות נחשבות שונות גם אם הן נותנות את אותה הצפנה. למשל, יש ארבע דרכים שונות לקבל AAA מ־AA, בהתאמה לארבע הפעולות לעיל.

קלט

  • שורה $1$: מחרוזת שאורכה לכל היותר 100.

פלט

  • שורה $1$: מספר הדרכים השונות ליצור מחרוזת זו בפעולה אחת או יותר ברצף על מחרוזת מקור כלשהי באורך לפחות 2. אם אין דרכים כאלה, הדפיסו אפס.

דוגמאות

קלט 1

ABABA

פלט 1

6

הערה

אלה הדרכים השונות ליצור ABABA:

  1. התחילו במחרוזת: ABA -> AB+ABA
  2. התחילו במחרוזת: ABA -> ABA+BA
  3. התחילו במחרוזת: AB -> AB+A -> AB+ABA
  4. התחילו במחרוזת: AB -> AB+A -> ABA+BA
  5. התחילו במחרוזת: BA -> A+BA -> AB+ABA
  6. התחילו במחרוזת: BA -> A+BA -> ABA+BA

מחברי הבעיה: Brian Dean ו־Lewin Gan

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.