QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#18125. בעיית בנייה משעממת

Statistics

תיאור הבעיה

בעיית הבנייה המשעממת ביותר בעולם היא לקרוא $n, m$ ולהדפיס מטריצה המקיימת את תנאים 1, 2, 3, 4, 5, 6, 7, 8.

נתונים ארבעה מספרים שלמים $a, b, n, s$ ($a \neq b$). עליך לבנות סדרה $c$ באורך $n$ כך ש:

  • עבור כל $1 \le i \le n$, מתקיים $c_i \in \{a, b\}$;
  • לא קיים תת-מערך רציף $c_l, c_{l+1}, \dots, c_r$ שסכומו שווה בדיוק ל-$s$.

באופן פורמלי יותר, לא קיימים מספרים שלמים $(l, r)$ המקיימים $1 \le l \le r \le n$ כך ש-$c_l + c_{l+1} + \dots + c_r = s$.

עבור כל מקרה בדיקה, קבע האם קיימת סדרה כזו:

  • אם היא קיימת, הדפס YES, והדפס סדרה חוקית כלשהי;
  • אחרת, הדפס NO.

קלט

השורה הראשונה מכילה מספר שלם $T$ ($1 \le T \le 10^5$), המציין את מספר מקרי הבדיקה.

כל אחת מ-$T$ השורות הבאות מכילה ארבעה מספרים שלמים $a, b, n, s$ ($1 \le a, b, s \le 10^9$, $1 \le n \le 5 \cdot 10^5$, $a \neq b$).

מובטח כי סכום כל ערכי ה-$n$ אינו עולה על $5 \cdot 10^5$.

פלט

עבור כל מקרה בדיקה:

  • אם אין פתרון, הדפס שורה המכילה NO;
  • אם יש פתרון, הדפס תחילה שורה המכילה YES, ולאחר מכן הדפס שורה המכילה $n$ מספרים שלמים המייצגים את הסדרה שבנית.

אם קיימות מספר תשובות חוקיות, הדפס אחת מהן.

דוגמאות

קלט 1

3
2 4 6 8
2 5 5 9
3 4 3 7

פלט 1

NO
YES
2 5 5 5 2
YES
4 4 4

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.