1767D - Playoff - CodeForces Solution


combinatorics constructive algorithms dp greedy math *1500

Please click on ads to support us..

Python Code:

n = int(input())

st = input()
s = 0
for i in range(n):
    if st[i] == '1':
        s += 1

l = 2 ** s
r = (2 ** n) - (2 ** (n - s) ) + 2

out = ""

for i in range(l, r):
    out += str(i) + " "
print(out)

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define en '\n'
#define vec vector
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define in(x,y) (y).find((x))!=(y).end()
#define nin(x,y) (y).find((x))==(y).end()

#ifdef DEBUG
#include "template/debug.h"
#else
#define debug(x...)
#define enhance(x)
#endif 


void solve() {
	int n; cin>>n;
	string s; cin>>s;
	vec<int> pow2(n+1);
	pow2[0]=1;
	int x=0, y=0;
	for(int i=0; i<n; ++i){
		if(s[i]=='1') ++x;
		else ++y;
		pow2[i+1]=2*pow2[i];
	}
	
	if(x==0){
		cout<<1<<en; return;
	}
	if(y==0){
		cout<<pow2[n]<<en; return;
	}
	int a=pow2[x], b=pow2[n]-pow2[y]+1;
	for(int i=a; i<=b; ++i){
		cout<<i<<" ";
	}
}

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int t=1;
	//cin>>t;
	while(t--) solve();
}


Comments

Submit
0 Comments
More Questions

Happy segments
Cyclic shifts
Zoos
Build a graph
Almost correct bracket sequence
Count of integers
Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons