QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#343484 | #8004. Bit Component | ucup-team1525# | WA | 1ms | 3940kb | C++17 | 2.1kb | 2024-03-02 17:26:25 | 2024-03-02 17:26:26 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int n;
int main()
{
// int n=4;
// for (int i=0;i<(1<<n);++i)
// {
// int x=i^(i>>1);
// for (int j=n-1;j>=0;--j)
// printf("%d",(x>>j)&1);
// puts("");
// }
// printf("%b\n",i^(i>>1))
scanf("%d",&n);
if (n<=6)
{
if (n==1)
{
puts("YES");
puts("1");
}
if (n==3)
{
puts("YES");
puts("2 3 1");
}
if (n==2||n==4||n==5||n==6)
puts("NO");
return 0;
}
int p=0;
while ((1<<p)<=n)
++p;
int q=(1<<p);
int oo=q/4*3+1;
if (oo>n)
{
puts("NO");
return 0;
}
vector<int> ans,ans1;
for (int i=1;i<(1<<p);++i)
{
int x=i^(i>>1);
if (x>n)
continue;
int o=x>>(p-2);
if (o==0)
{
ans.push_back(x);
}
if (o==1)
{
if ((x+1)==(1<<(p-1)))
{
ans.push_back(1<<(p-2));
if ((1<<(p-2))+(1<<(p-1))<=n)
ans.push_back((1<<(p-2))+(1<<(p-1)));
}
if (x==(1<<p-2))
continue;
ans.push_back(x);
if (x+(1<<(p-1))<=n&&(x+(1<<p-1)!=oo))
ans.push_back(x+(1<<(p-1)));
}
if (o==2)
{
ans1.push_back(x);
}
if (o==3)
{
if (x==oo)
ans.push_back(x);
}
// ans.push_back(x);
// if (i>=(1<<(p-2))&&x+(1<<(p-1))<=n)
// if ()
}
puts("YES");
for (int x:ans)
printf("%d ",x);
ans1.pop_back();
for (int i=ans1.size()-1;i>=0;--i)
printf("%d ",ans1[i]);
printf("%d",(1<<(p-1)));
// sort(ans.begin(),ans.end());
// for (int i=0;i<n;++i)
// if (ans[i]!=i+1)
// puts("gg");
return 0;
}
// 01111111
// ...
// 01000001
// 01000000
// 11000001
// 10000001
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3720kb
input:
1
output:
YES 1
result:
ok answer is 1
Test #2:
score: 0
Accepted
time: 0ms
memory: 3940kb
input:
2
output:
NO
result:
ok answer is 0
Test #3:
score: 0
Accepted
time: 0ms
memory: 3712kb
input:
3
output:
YES 2 3 1
result:
ok answer is 1
Test #4:
score: 0
Accepted
time: 1ms
memory: 3616kb
input:
4
output:
NO
result:
ok answer is 0
Test #5:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
5
output:
NO
result:
ok answer is 0
Test #6:
score: 0
Accepted
time: 1ms
memory: 3644kb
input:
6
output:
NO
result:
ok answer is 0
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3848kb
input:
7
output:
YES 1 2 6 3 7 5 4
result:
wrong answer Participant's answer is incorrect