提出 #15172713


ソースコード 拡げる

#include <iostream>
#include <fstream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <ctime>
#include <bitset>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define ld long double
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fast_io cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld eps = (ld)1 / 1e6;
ll inf = LLONG_MAX, mod1 = 1e9 + 7, mod2 = 998244353;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ll md[200010][2];
ll solve(ll x)
{
    if (!x) return 0;
    bitset<40> bt = x;
    ll t = bt.count();
    return (1 + solve(x % t));
}

int main()
{
    fast_io;
    ll n, i, k0 = 0, n1 = 0, n2 = 0, nw;
    string a;
    cin >> n >> a;
    for (i = 0; i < n; i++)
        if (a[i] == '1') k0++;
    md[0][0] = md[0][1] = 1;
    for (i = 1; i < n; i++)
    {
        if (k0 > 1) md[i][0] = (2 * md[i - 1][0]) % (k0 - 1);
        md[i][1] = (2 * md[i - 1][1]) % (k0 + 1);
    }
    for (i = 0; i < n; i++)
    {
        if (a[i] == '0') continue;
        if (k0 > 1) n1 = (n1 + md[n - i - 1][0]) % (k0 - 1);
        n2 = (n2 + md[n - i - 1][1]) % (k0 + 1);
    }
    for (i = 0; i < n; i++)
    {
        if (k0 == 1 && a[i] == '1')
        {
            cout << "0\n";
            continue;
        }
        if (a[i] == '0') nw = (n2 + md[n - i - 1][1]) % (k0 + 1);
        else nw = (n1 - md[n - i - 1][0] + k0 - 1) % (k0 - 1);
        cout << 1 + solve(nw) << '\n';
    }
    return 0;
}

提出情報

提出日時
問題 D - Anything Goes to Zero
ユーザ thirty_something
言語 C++ (GCC 9.2.1)
得点 400
コード長 2819 Byte
結果 AC
実行時間 39 ms
メモリ 6860 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 21
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
hand_01.txt AC 6 ms 3548 KiB
hand_02.txt AC 2 ms 3520 KiB
hand_03.txt AC 13 ms 5092 KiB
hand_04.txt AC 6 ms 3684 KiB
hand_05.txt AC 32 ms 6860 KiB
hand_06.txt AC 28 ms 6716 KiB
hand_07.txt AC 36 ms 6796 KiB
random_01.txt AC 39 ms 6800 KiB
random_02.txt AC 39 ms 6784 KiB
random_03.txt AC 38 ms 6732 KiB
random_04.txt AC 35 ms 6716 KiB
random_05.txt AC 29 ms 6104 KiB
random_06.txt AC 7 ms 3600 KiB
random_07.txt AC 28 ms 5484 KiB
random_08.txt AC 14 ms 4336 KiB
random_09.txt AC 33 ms 6680 KiB
random_10.txt AC 13 ms 4332 KiB
random_11.txt AC 32 ms 6200 KiB
random_12.txt AC 24 ms 5292 KiB
sample_01.txt AC 5 ms 3484 KiB
sample_02.txt AC 2 ms 3544 KiB