QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#592217 | #6818. Barrel Theory | tosania | WA | 0ms | 3796kb | C++14 | 4.3kb | 2024-09-26 21:14:53 | 2024-09-26 21:14:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
int T;
inline int read() {
int al = 0, fh = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
al = -1;
ch = getchar();
}
while (ch <= '9' && ch >= '0') {
al = al * 10 + ch - '0';
ch = getchar();
}
return al * fh;
}
inline int lowbit(int a) {
return a & (-a);
}
signed main() {
T = read();
for (int yyc = 1; yyc <= T; yyc++) {
int n, m;
n = read();
m = read();
if (n == 1) {
cout << "NO\n";
}
else if (n == 2) {
if (m % 2 == 0) {
cout << "YES\n" << m / 2 << " " << m / 2 << endl;
}
else {
if (m == 3) {
cout << "NO\n";
}
else {
int ok = 0;
for (int i = 1; i <= m; i++) {
if ((i ^ (m - i)) < min(i, m - i)) {
cout << "YES\n" << i << " " << m - i << endl;
ok = 1;
break;
}
}
if (ok == 0) {
cout << "NO\n";
}
}
}
}
else if (m % 2 == 0) {
if (n % 2 == 0) {
cout << "YES\n";
for (int i = 1; i <= n - 2; i++) {
printf("1 ");
m--;
}
printf("%lld %lld\n", m / (int)2, m / (int)2);
}
else {
if (n == 3) {
if (lowbit(m) != m) {
cout << "YES\n";
cout << m / 2 << " " << m / 2 - lowbit(m / 2) << " " << lowbit(m / 2) << endl;
}
else if (m >= 16) {
cout << "YES\n";
cout << 3 * m / 16 << " " << 6 * m / 16 << " " << 7 * m / 16 << endl;
}
else {
cout << "NO\n";
}
}
else {
int k = m - (n - 3);
if (k <= 4) {
cout << "NO\n";
}
else if (lowbit(k) != k) {
cout << "YES\n";
for (int i = 1; i <= n - 3; i++) {
cout << 1 << " ";
}
cout << k / 2 << " " << k / 2 - lowbit(k / 2) << " " << lowbit(k / 2)<<endl;
}
else {
cout << "YES\n";
for (int i = 1; i <= n - 5; i++) {
cout << 1 << " ";
}
cout << "2 2 ";
k -= 2;
cout << k / 2 << " " << k / 2 - lowbit(k / 2) << " " << lowbit(k / 2)<<endl;
}
}
}
}
else {
if (m < 2 * n + 1) {
cout << "NO\n";
}
else {
if (n % 2 == 0) {
cout << "YES\n";
cout << 3 << " ";
for (int i = 2; i <= n - 2; i++) {
cout << 2 << " ";
}
m -= 2 * (n - 2) + 1;
cout << m / 2 << " " << m / 2 << endl;
}
else {
int k = m - (n - 3) * 2;
if ((lowbit(k - 1) != k - 1) && (lowbit(k - 3) != k - 3)) {
cout << "YES\n";
for (int i = 1; i <= n - 3; i++) {
cout << 2 << " ";
}
cout << k / 2 << " ";
int w = lowbit(k / 2);
if (w == 1)
w = lowbit(k / 2 - w);
if ((k / 2 - w) % 2 == 0) {
cout << k / 2 - w + 1 << " " << w << endl;
}
else cout << k / 2 - w << " " << w + 1 << endl;
}
else if ((lowbit(k - 1) == k - 1)) {
if (n == 3) {
if (k <= 17) {
cout << "NO\n";
}
else {
cout << "YES\n";
cout << 3 * (k - 1) / 16 << " " << 6 * (k - 1) / 16 + 1 << " " << 7 * (k - 1) / 16 << endl;
}
}
else {
cout << "YES\n";
cout << "3 3 ";
for (int i = 3; i <= n - 3; i++) {
cout << 2 << " ";
}
k -= 2;
cout << k / 2 << " ";
int w = lowbit(k / 2);
if (w == 1)
w = lowbit(k / 2 - w);
if ((k / 2 - w) % 2 == 0) {
cout << k / 2 - w + 1 << " " << w << endl;
}
else cout << k / 2 - w << " " << w + 1 << endl;
}
}
else {
if (n == 3) {
if (k <= 19) {
cout << "NO\n";
}
else {
if(yyc==1881){
return 0;
}
cout << "YES\n";
cout << 7 << " " << (k - 7) / 2 + 1 << " " << (k - 7) / 2 - 1 << endl;
}
}
else {
cout << "YES\n";
cout << 4 << " " << 4 << " ";
for (int i = 3; i <= n - 3; i++) {
cout << 2 << " ";
}
k -= 4;
cout << k / 2 << " ";
int w = lowbit(k / 2);
if (w == 1)
w = lowbit(k / 2 - w);
if ((k / 2 - w) % 2 == 0) {
cout << k / 2 - w + 1 << " " << w << endl;
}
else cout << k / 2 - w << " " << w + 1 << endl;
}
}
}
}
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3796kb
input:
3 6 7 5 17 4 4
output:
NO YES 2 2 6 5 2 YES 1 1 1 1
result:
ok T=3 (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3752kb
input:
4194 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 1 11 1 12 1 13 1 14 1 15 1 16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 1 26 1 27 1 28 1 29 1 30 1 31 1 32 1 33 1 34 1 35 1 36 1 37 1 38 1 39 1 40 1 41 1 42 1 43 1 44 1 45 1 46 1 47 1 48 1 49 1 50 1 51 1 52 1 53 1 54 1 55 1 56 1 57 1 58 1 59 1 60 1 61...
output:
NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO NO ...
result:
wrong answer wa on testcase 1881 (test case 1881)