Codeforces Round #671 (Div. 2)
Codeforces Round #671 (Div. 2)
A
int main(){
int t=read();
while(t--){
int n;
cin>>n;
string s;
cin>>s;
int e1=0,o1=0,e2=0,o2=0;
int focus=0;
if(s.size()%2==1){
focus=1;
}
else focus=2;
for(int i=s.size()-1,t=n;i>=0;i--,t--){
int type=0;
if((s[i]-'0')%2==0){
type=2;
}
else type=1;
if(type==1){
if(t%2==1) o1++;
else o2++;
}
else{
if(t%2==1) e1++;
else e2++;
}
}
if(focus==1){
if(o1>0){
cout<<"1
";
}
else{
cout<<"2
";
}
}
else{
if(e2>0){
cout<<"2
";
}
else{
cout<<"1
";
}
}
}
return 0;
}
B
int main(){
int t=read();
while(t--){
ll k=read();
int cnt=0;
ll now=0;
ll p=1;
while(k>=now*2+p*p){
k-=now*2+p*p;
now=now*2+p*p;
p*=2;
cnt++;
// cout<<now<<'
';
}
cout<<cnt<<'
';
}
return 0;
}
C
int vn[1001];
int main(){
int t=read();
while(t--){
int n=read(),q=read();
int ans=0,cnt=0;
bool ch=true;
for(int i=1;i<=n;++i){
vn[i]=read();
int diff=vn[i]-q;
if(diff!=0)ch=false,cnt++;
ans+=diff;
}
if(ch==true){
cout<<'0'<<'
';
}
else if(ans==0||cnt<n){
cout<<'1'<<'
';
}
else{
cout<<'2'<<'
';
}
}
return 0;
}
D
int main(){
int n=read();
vector<int>np(n);
for(int i=0;i<n;++i)np[i]=read();
sort(np.begin(),np.end(),greater<int>());
vector<int>ans;
vector<int>ps;
int pt1=0,pt2=ceil(n/2.0);
for(int i=0;i<n;++i){
if(i%2==0)
ans.push_back(np[pt1++]);
else{
if(pt2<n&&np[pt2]<ans.back()){
ans.push_back(np[pt2++]);
}
else{
bool ms=false;
while(pt2<n&&np[pt2]>=ans.back()){
ps.push_back(np[pt2++]);
}
if(pt2<n&&np[pt2]<ans.back()){
ans.push_back(np[pt2++]);
}
else{
ans.push_back(ps.back());
ps.pop_back();
}
}
}
}
int cnt=0;
for(int i=0;i<n;++i){
if(i-1>=0&&i+1<n){
if(ans[i]<ans[i-1]&&ans[i]<ans[i+1])
cnt++;
}
}
cout<<cnt<<'
';
for(int i=0;i<n;++i)
cout<<ans[i]<<' ';
return 0;
}
E
vector<int>ans;
vector<int>primelist;
vector<int>primecnt;
int main(){
int t=read();
while(t--){
ans.clear();
primecnt.clear();
primelist.clear();
int n=read();
bool isp=true;
for(ll i=2;i*i<=n;++i){
if(n%i==0){
isp=false;
primelist.push_back(i);
primecnt.push_back(1);
n/=i;
while(n%i==0){
n/=i;
++primecnt.back();
}
}
}
if(isp==true){
cout<<n<<'
';
cout<<0<<'
';
continue;
}
if(n!=1){
// cout<<"Yes:
";
primelist.push_back(n);
primecnt.push_back(1);
}
int cnt=0;
vector<int>pre;
pre.push_back(1);
for(int i=0;i<primelist.size();++i){
vector<int>ist;
int now=1;
for(int j=1;j<=primecnt[i];++j){
now*=primelist[i];
for(int k=0;k<pre.size();++k){
ist.push_back(now*pre[k]);
}
}
if(i+1<primelist.size())
for(int u=ist.size()-1;u>=0;--u)
ans.push_back(ist[u]);
else{
if(ist.size()!=2)
ans.push_back(ist.back());
for(int u=ist.size()-2;u>=0;--u)
if(u!=1)ans.push_back(ist[u]);
if(ist.size()>1)
ans.push_back(ist[1]);
}
for(int u:ist)
pre.push_back(u);
}
for(int i=0;i<ans.size();++i){
cout<<ans[i]<<' ';
if(__gcd(ans[i],ans[(i+1<ans.size()?i+1:0)])==1){
//cout<<ans[i]*ans[(i+1<ans.size()?i+1:0)]<<' ';
cnt++;
}
}
cout<<'
';
cout<<cnt<<'
';
// cout<<"end
";
}
return 0;
}