QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#491241 | #6569. Splitting Pairs | SmallAoPigBigPiPig# | RE | 1ms | 4004kb | C++17 | 2.3kb | 2024-07-25 17:57:30 | 2024-07-25 17:57:30 |
Judging History
answer
#include<bits/stdc++.h>
const int MAXN = 50011;
typedef std::pair<int,int> pii;
typedef long long ll;
typedef std::vector<int> P;
std::map<P,int>f;
int cnt[1<<10];
std::vector<P>seq[2011];
void dfs(P a,P b,int x,int c,int up,int cur)
{
if(x==a.size())
{
if(c!=up)return;
seq[cur].emplace_back(b);
return;
}
if(c<up)
{
for(int k=1;k<=a[x]/2;++k)
{
b.emplace_back(k),b.emplace_back(a[x]-k);
dfs(a,b,x+1,c+1,up,cur);
b.pop_back(),b.pop_back();
}
}
b.emplace_back(a[x]);
dfs(a,b,x+1,c,up,cur);
}
bool solve(P a,int dep)
{
std::sort(a.begin(),a.end());
if(f.count(a))return f[a];
if(a.back()==1)return f[a]=0;
int n=a.size();
for(int s=1;s<(1<<n);++s)
{
if(cnt[s]*2>n)continue;
seq[dep].clear();
P b,c;
for(int i=0;i<n;++i)
if(!(s&(1<<i)))b.emplace_back(a[i]);
dfs(b,c,0,0,cnt[s],dep);
for(auto q:seq[dep])
{
// printf("From ");
// for(auto x:a)printf("%d ",x);
// printf(" To ");
// for(auto x:q)printf("%d ",x);
// puts("");
if(!solve(q,dep+1))return f[a]=1;
}
}
return f[a]=0;
}
ll a[2011];
int main()
{
for(int s=1;s<(1<<10);++s)cnt[s]=cnt[s&(s-1)]+1;
int task;
scanf("%d",&task);
while(task--)
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%lld",&a[i]);
std::sort(a+1,a+n+1);
bool odd=0,even=0;
for(int i=1;i<=n;++i)
if(a[i]&1)odd=1;
else even=1;
if(n&1)
{
if(odd)
{
puts(even?"1":"0");
continue;
}
bool all= a[n]==a[1];
bool ans=1;
if(even&&all)
{
puts("0");
continue;
}
int mul=2;
for(int x=a[1];x%2==0;x/=2)mul*=2;
bool flag=1;
for(int i=1;i<=n;++i)
if((a[i]-a[1])%mul)flag=0;
if(flag)ans=0;
printf("%d\n",ans);
}
else
{
puts(even?"1":"0");
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3772kb
input:
4 3 1 1 1 3 1 1 2 3 2 2 2 4 4 4 4 4
output:
0 1 0 1
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 4004kb
input:
1000 10 16 16 16 16 16 16 16 16 16 16 10 16 16 16 16 16 16 16 16 17 16 10 16 16 16 16 16 16 16 18 16 16 10 16 16 16 19 16 16 16 16 16 16 10 16 16 16 16 20 16 16 16 16 16 10 17 16 16 16 17 16 16 16 16 16 10 16 16 16 16 16 16 16 16 18 17 10 16 16 19 16 16 16 16 17 16 16 10 17 16 16 16 16 16 16 20 16 1...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
ok 1000 lines
Test #3:
score: 0
Accepted
time: 1ms
memory: 3832kb
input:
1000 2 4 4 2 5 4 2 4 6 2 7 4 2 4 8 2 5 5 2 6 5 2 7 5 2 8 5 2 6 6 2 7 6 2 8 6 2 7 7 2 7 8 2 8 8 3 4 4 4 3 4 5 4 3 4 4 6 3 4 7 4 3 8 4 4 3 4 5 5 3 6 4 5 3 4 5 7 3 8 5 4 3 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 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 ...
result:
ok 1000 lines
Test #5:
score: -100
Runtime Error
input:
1000 49 70984400896 988463235072 689895899136 448069107712 139972313088 432801841152 571884961792 572723822592 147287179264 253252075520 941688356864 914542821376 100344528896 317945020416 796062121984 504306335744 30417092608 36054237184 652314935296 547994206208 335393325056 959203770368 824583389...