QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#290080 | #4617. Arithmetic Subsequence | yspm | RE | 0ms | 0kb | C++20 | 1.3kb | 2023-12-24 12:35:19 | 2023-12-24 12:35:19 |
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
using namespace std;
template<typename T>inline void ckmax(T &x,T y){x=x<y?y:x;}
template<typename T>inline void ckmin(T &x,T y){x=x>y?y:x;}
template<typename T=int>inline T read(){
T res=0,f=1; char k;
while(!isdigit(k=getchar())) if(k=='-') f=-1;
while(isdigit(k)) res=res*10+k-'0',k=getchar();
return res*f;
}
template<typename T>inline void print(T x,bool fl=1){
if(x<0) putchar('-'),x=-x;
if(x>=10) print(x/10,0);
putchar(x%10+'0');
if(fl) putchar('\n');
}
const int N=5010;
int a[N],b[N],n,ta[N],tb[N];
bool Fail=0;
inline void solve(int l,int r){
if(r<l) return ;
if(a[l]==a[r]){
if(r-l+1>=3) Fail=1;
return ;
}
int c1=l-1,c2=r+1;
rep(i,l,r) if(a[i]&1) ta[++c1]=a[i]/2,tb[c1]=b[i];
rep(i,l,r) if(a[i]%2==0) ta[--c1]=a[i]/2,tb[c1]=b[i];
rep(i,l,r) a[i]=ta[i],b[i]=tb[i];
solve(l,c1); solve(c2,r);
return ;
}
int main(){
int T=read();
while(T--){
n=read();
for(int i=1;i<=n;++i) b[i]=a[i]=read();
solve(1,n);
if(Fail){
Fail=0;
puts("NO");
continue;
}
puts("YES");
for(int i=1;i<n;++i) printf("%d ",b[i]);
printf("%d\n",b[n]);
}
return 0;
}
詳細信息
Test #1:
score: 0
Runtime Error
input:
25 4 3 6 8 9 5 1 1 1 1 1 5000 204869248 184063453 335277313 805198752 988635160 266844506 494544568 842685418 516257494 110006739 727397507 931812983 898605116 670474885 536302721 818724782 251547299 883494814 479828194 573135914 408419766 283100869 472145517 996777784 393702645 555881361 835407611 ...
output:
YES 6 9 0 0 NO NO YES 111386099 120962787 379908907 372090340 246439823 599735511 372090340 833384817 615292649 177398697 636804929 168177061 141863857 150780721 826051421 303568737 84653049 529608145 331536173 557405697 247336645 215980121 567139173 674717349 283819261 578722069 693349277 257777961...