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.