Submission #15186239


Source Code Expand

#include <bits/stdc++.h>

// definitions
#define __Imperial_Lord__ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define _cps CLOCKS_PER_SEC
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c <<endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d <<endl
#define exec cerr<<"Time taken : "<<(ld)(clock())/_cps<<"s"<<endl
#define mod1 998244353
#define mod 1000000007
#define pi 3.1415926535897932384

using namespace std;

// alias name for common data types
typedef vector<long long> vl;
typedef vector<long double> vld;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dql;
typedef deque <char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const ll INF=1e18;

template <class ...Args>
istream &read_args(Args &...args) {return (cin >> ... >> args);}
#define read(...)   __VA_ARGS__; read_args(__VA_ARGS__)

// cin and cout overloaded for vectors
template<typename T>    istream& operator>>(istream& is,  vector<T>& v)
{
    for (auto& i : v) 
        is >> i;        
    return is;
}
template<typename T>    ostream& operator<<(ostream& os,  vector<T>& v)
{
    for (auto& i : v) 
        os << i << ' '; 
        return os;
}

ll pl(ll a, ll b, ll md)
{
    ll v=a+b;
    while(v<0) v+=md;
    while(v>=md) v-=md;

    return v;
}

ll modexp(ll x, ll ex, ll md) 
{
    ll ans = 1ll;
    while (ex > 0) 
    {
        if (ex & 1ll) ans = (ans * x)%md;
        ex >>= 1ll;
        x = (x * x)%md;
    }
    return ans;
}

// code beigns in main
int main()
{
    __Imperial_Lord__
    ll t=1;
    // cin >> t;

    while(t--)
    {
        ll read(n);
        string read(s);

        ll cnt=0;
        rep(i,0,n) if(s[i]=='1') cnt++;

        if(cnt==0)
        {
            rep(i,0,n)
            p1(1);
            return 0;
        }

        ll a1=0,a2=0;
        rep(i,0,n)
        {   
            if(s[i]=='1')
            {
                if(cnt>1)
                    a1=pl(a1,modexp(2,n-i-1,cnt-1),cnt-1); 
                a2=pl(a2,modexp(2,n-i-1,cnt+1),cnt+1);               
            }
        }

        rep(i,0,n)
        {
            if(s[i]=='1')
            {
                if(cnt==1)
                {
                    p1(0); continue;
                }

                ll l1=pl(a1,-modexp(2,n-i-1,cnt-1),cnt-1);
                while(l1<0) l1+=cnt-1;
                ll ans=1;
                while(l1)
                {
                    ans++;
                    l1%=(high(l1));
                }
                p1(ans);
            }
            else
            {
                ll l1=pl(a2,modexp(2,n-i-1,cnt+1),cnt+1);
                ll ans=1;
                while(l1)
                {
                    ans++;
                    l1%=(high(l1));
                }
                p1(ans);
            }
        }
    }   
    exec;
}

Submission Info

Submission Time
Task D - Anything Goes to Zero
User Imperial_Lord
Language C++ (GCC 9.2.1)
Score 400
Code Size 3646 Byte
Status AC
Exec Time 390 ms
Memory 3960 KiB

Compile Error

./Main.cpp: In function ‘std::ostream& operator<<(std::ostream&, std::vector<_Tp>&)’:
./Main.cpp:56:5: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
   56 |     for (auto& i : v)
      |     ^~~
./Main.cpp:58:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
   58 |         return os;
      |         ^~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 21
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
hand_01.txt AC 7 ms 3556 KiB
hand_02.txt AC 7 ms 3780 KiB
hand_03.txt AC 163 ms 3808 KiB
hand_04.txt AC 22 ms 3700 KiB
hand_05.txt AC 331 ms 3824 KiB
hand_06.txt AC 326 ms 3816 KiB
hand_07.txt AC 364 ms 3812 KiB
random_01.txt AC 386 ms 3800 KiB
random_02.txt AC 385 ms 3824 KiB
random_03.txt AC 390 ms 3824 KiB
random_04.txt AC 389 ms 3884 KiB
random_05.txt AC 307 ms 3804 KiB
random_06.txt AC 28 ms 3708 KiB
random_07.txt AC 242 ms 3960 KiB
random_08.txt AC 87 ms 3792 KiB
random_09.txt AC 368 ms 3808 KiB
random_10.txt AC 88 ms 3936 KiB
random_11.txt AC 309 ms 3860 KiB
random_12.txt AC 212 ms 3888 KiB
sample_01.txt AC 6 ms 3736 KiB
sample_02.txt AC 2 ms 3672 KiB