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$)。你需要構造一個長度為 $n$ 的序列 $c$,滿足:

  • 對於每個 $1 \le i \le n$,$c_i \in \{a, b\}$;
  • 不存在一個連續子陣列 $c_l, c_{l+1}, \dots, c_r$,其和恰好為 $s$。

更正式地,不存在滿足 $1 \le l \le r \le n$ 的整數對 $(l, r)$ 使得 $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.