QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#59085#95. RadixhhblwAC ✓923ms102140kbC++985.1kb2022-10-27 22:14:342022-10-27 22:14:38

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-27 22:14:38]
  • 评测
  • 测评结果:AC
  • 用时:923ms
  • 内存:102140kb
  • [2022-10-27 22:14:34]
  • 提交

answer

#include <iostream>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <complex>
#include <cmath>
#include <cassert>
#include <cstring>

using namespace std;

typedef unsigned short dig;
typedef unsigned int u64;

#define DIGM ( ~(dig)(0) )
#define DIGL ( 8 * sizeof(dig) )

#define sz size()

typedef complex<long double> base;

typedef vector<dig> bi;

int rev[1000000];
base wlen_pw[1000000];
base fa[1000000];
base fb[1000000];

#define BASE10 100
#define BASE10L 2

bi digits[BASE10+1];

#define MAXN (10000000+100500)

char s[MAXN];

void print(bi x, char * s) {
    int j = DIGL - 1;
    if(!x.sz) {
        *s++ = '0';
        *s++ = 0;
        return ;
    }
    while( !((x[x.sz-1]>>j)&1) )
        --j;
    while(j >= 0)
        *s++ = '0' + ((x[x.sz-1]>>(j--))&1);
    int i = x.sz-2;
    while(i>=0) {
        j = DIGL - 1;
        do
            *s++ = '0' + ((x[i]>>(j--))&1);
        while(j >= 0);
        --i;
    }
    *s++ = 0;
}

void fft (base a[], int n, bool invert) {
	for (int i=0; i<n; ++i)
		if (i < rev[i])
			swap (a[i], a[rev[i]]);

	for (int len=2; len<=n; len<<=1) {
		long double ang = 2*M_PI/len * (invert?-1:+1);
		int len2 = len>>1;

		base wlen (cosl(ang), sinl(ang));
		wlen_pw[0] = base (1, 0);
		for (int i=1; i<len2; ++i)
			wlen_pw[i] = wlen_pw[i-1] * wlen;

		for (int i=0; i<n; i+=len) {
			base t,
				*pu = a+i,
				*pv = a+i+len2,
				*pu_end = a+i+len2,
				*pw = wlen_pw;
			for (; pu!=pu_end; ++pu, ++pv, ++pw) {
				t = *pv * *pw;
				*pv = *pu - t;
				*pu += t;
			}
		}
	}

	if (invert)
		for (int i=0; i<n; ++i)
			a[i] /= n;
}

void calc_rev (int n, int log_n) {
	for (int i=0; i<n; ++i) {
		rev[i] = 0;
		for (int j=0; j<log_n; ++j)
			if (i & (1<<j))
				rev[i] |= 1<<(log_n-1-j);
	}
}

typedef vector<dig> bi;

bi mul(bi op1, bi op2) {
	size_t n = 1;
	size_t logn = 0;
	while (n < max (op1.size(), op2.size())) n <<= 1, logn += 1;
	n <<= 1; logn += 1;
	for(int i = 0; i < op1.sz; ++i) fa[i] = op1[i];
	for(int i = op1.sz; i < n; ++i) fa[i] = 0;
	for(int i = 0; i < op2.sz; ++i) fb[i] = op2[i];
	for(int i = op2.sz; i < n; ++i) fb[i] = 0;
    calc_rev(n, logn);
    //for(int i = 0; i < n; ++i) cerr << fa[i] << ' '; cerr << '\n';
    //for(int i = 0; i < n; ++i) cerr << fb[i] << ' '; cerr << '\n';
	fft (fa, n, false),  fft (fb, n, false);
	for (size_t i = 0; i < n; ++i)
		fa[i] *= fb[i];
	fft (fa, n, true);
	//for(int i = 0; i < n; ++i) cerr << fa[i] << ' '; cerr << '\n';
	bi res(n);
	unsigned long long t = 0, carry = 0;
	for (size_t i=0; i<n; ++i) {
	    t = (unsigned long long)(fa[i].real() + 0.5) + carry;
	    res[i] = (dig)(t & DIGM);
	    carry = t >> DIGL;
	}
	while(!res.empty() && !res.back())
        res.pop_back();
    return res;
}

/*bi mul(bi op1, bi op2) {
    bi res(op1.sz + op2.sz);
    for(int i = 0; i < op1.sz; ++i) {
        dig carry = 0;
        u64 t;
        int j;
        for(j = 0; j < op2.sz; ++j) {
            t = op1[i];
            t *= op2[j];
            t += res[i+j];
            t += carry;
            res[i+j] = t & DIGM;
            carry = t >> DIGL;
        }
        while(carry) {
            t = res[i+j] + carry;
            res[i+j] = t & DIGM;
            carry = t >> DIGL;
            ++j;
        }
    }
    while(res.sz > 0 && res[res.sz-1] == 0)
        res.pop_back();
    return res;
}*/

int max(int i, int j) { return i < j ? j : i; }

bi sum(bi op1, bi op2) {
    bi res(max(op1.sz, op2.sz)+1);
    dig carry = 0;
    u64 t;
    int i;
    for(i = 0; i < op1.sz && i < op2.sz; ++i) {
        t = op1[i];
        t += op2[i];
        t += carry;
        res[i] = t & DIGM;
        carry = t >> DIGL;
    }
    for(; i < op1.sz; ++i) {
        t = op1[i];
        t += carry;
        res[i] = t & DIGM;
        carry = t >> DIGL;
    }
    for(; i < op2.sz; ++i) {
        t = op2[i];
        t += carry;
        res[i] = t & DIGM;
        carry = t >> DIGL;
    }
    if(carry)
        res[i] = carry;
    while(res.sz > 0 && res[res.sz-1] == 0)
        res.pop_back();
    return res;
}

bi read(char * s) {
    int n = strlen(s);
    bi res((n + BASE10L)/BASE10L);
    int l = 0;
    for(int i = n; i > 0; i -= BASE10L) {
        char si = s[i];
        s[i] = 0;
        res[l++] = atoi(s+max(i-BASE10L, 0));
        s[i] = si;
    }
    return res;
}

bi step[20];

bi go(bi x) {
    if(!x.sz) return bi(0);
    if(x.sz <= 1) return bi(1, x[0]);
    int i = 1;
    while( (1<<(i-1)) < x.sz) ++i; --i;
    int l = (1 << (i-1));
    bi y = bi(x.begin() + l, x.end());
    x.resize(l);
    return sum(mul(go(y), step[i]) , go(x));
}

bi solve2(bi x) {
    step[0] = bi(1, 1);
    step[1] = bi(1, BASE10);
    for(int i = 2; (1<<(i-1)) < x.sz; ++i)
        step[i] = mul(step[i-1], step[i-1]);
    return go(x);
}


int main() {
    for(int i = 0; i <= BASE10; ++i) {
        digits[i] = bi(1, i);
    }
    gets(s);
    if( strlen(s) == 1 && s[0] == '0' ) { puts("0"); return 0; }
    bi input = read(s);
    bi ans = solve2(input);
    print(ans, s);
    puts(s);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 19ms
memory: 97728kb

input:

10

output:

1010

result:

ok single line: '1010'

Test #2:

score: 0
Accepted
time: 889ms
memory: 101852kb

input:

597957566157262226803677497510777455991626761264559988614457669085677203250013738814331245072642034373549417956185791709340992220221130366957656508036743993403080962539275320094985518620291369330942797378444207197057359810313358964818279403092139502412064613934576307715907477337040161649118829613955...

output:

100111100011000111100000110000011110101110110101010101011101000110110100010000011010110000011011101101001100001111001010101101011101101001001011111101110101111001111000011111011010000110000101110101111011000011101101101101001110100011000101001100101001010111100101001110100011010111011110001001111101...

result:

ok single line: '100111100011000111100000110000...1111000000000111000001011101010'

Test #3:

score: 0
Accepted
time: 877ms
memory: 101992kb

input:

483110965119940876441442992204223160806464660442414153243120909252878606030076792778847439291078650698150305373653015969227605530228092732490795710335940145779831283339118239495578872829460388954714728273052319850170894339706935755427756950232805626216087715806898908405518863387826278679136837699545...

output:

111111111001111101010010011110010101011011010101000001000101011000011000000100111001001111101011011010000101110010001101111110101110001010110100010110100000101011100011100000001010010011100101011101111110000001001011101001001111011111101000100101101110000111110001111101100111000100100000001111100000...

result:

ok single line: '111111111001111101010010011110...1111111100101010001011100110101'

Test #4:

score: 0
Accepted
time: 866ms
memory: 101952kb

input:

154127926048414596211200723665920182179012245364775852145648188921596957493619378377027074136882209967336873200822835453729529106301354722782821377888202450289302630323322278931857815337753340324232675601678901493027792878050242540762383847368703395912773599602963990729794991895855818212696142597356...

output:

101000110001101001111110100001110000101101001011111011111101101011001011000001010101001011101111111000111001010111000010010011111000110110100011011111000111110111110111101001111100100011111101000111000111111000000010111110111011011110001010100010011000011101001111100010101000011100100100111010000101...

result:

ok single line: '101000110001101001111110100001...0000011010001011110101110101101'

Test #5:

score: 0
Accepted
time: 859ms
memory: 102072kb

input:

233715838025755754385549681333056968427114985992967984485309708005232763651652926918342136761941460429673917007685489025602783707760333117905604634379122379208282667290579752809841029266408214043826186410248929327372428663728670039829872804332976755621091140356205347940009715167801538079300375320825...

output:

111101110101001101111111110110101110111001000001111000001100100000111110000110000111010000110000011111110110001110101000101100101010010111000111100101000011001010010010010110000101000100010100110100000110101001101001011101101100000010000000010101110001100101111111110111110110000001001100001001110010...

result:

ok single line: '111101110101001101111111110110...0111101010100110111011000100110'

Test #6:

score: 0
Accepted
time: 891ms
memory: 102132kb

input:

279925616892965779026729656483050577147813156413112596056540883676869327131046328146802906994361332781145180108605882603183486902403734635889350989349262602969584226162336083188470448432483703315011514341059942871180114422658030089551749159504076950540051585488310977951982062005759576883130104014647...

output:

100101000001110100001100110011011001011010011010111100101100000000000001010011001110000101101111010010110011001110101010001010100111111100101101011111001011110001010101110010010111101010010000110110110001010110001011001110101100000101111110111010110011010101111010111010110000001111001111011110001000...

result:

ok single line: '100101000001110100001100110011...1010010011110100011001001101011'

Test #7:

score: 0
Accepted
time: 849ms
memory: 102140kb

input:

232965663631288125024535090861117689026844202668304522776894254011787424768962484466640911114226662608351703571828575544071162305004494190056927951025894450962216317114053319595955362707180930389702974746009340861051338448410164166726000907911885034017436694594845803054669965244763102900325469569489...

output:

111101101000100001000101011010101011111001001100010111101000100011011101001011011011111111100001100001101100100001111110110011101100100011000010010010100011000010011100000000001000100000101010100111100001000010000011101110010111011111111001101001100110100110101101100111011111100101110110100111000011...

result:

ok single line: '111101101000100001000101011010...1010111111111101111111011010000'

Test #8:

score: 0
Accepted
time: 851ms
memory: 102032kb

input:

571648678189573028195609652980617995466383685953042701426781012173222574690413574846801552558163533666354876719854527253287224644361732115191443135824611071680218259959784262747513762842413094686894395427054917840931688925026390488431094729625358384065657774583998639282821459404649244058736529778467...

output:

100101110011110000001110001111101100000110010000001011111001111000011100011001110000100000011101100010011100101001110010001001101010110010011001110001001000000111101110111000111111000111000110110110010111001011111111101011010101011101000011100011100111111100101011100001001111011010011010001101010110...

result:

ok single line: '100101110011110000001110001111...1000100000110001010011101110000'

Test #9:

score: 0
Accepted
time: 859ms
memory: 101988kb

input:

280180466017115693382515599342508857451866984076546848865594362506304677404374022129172442257842899237527671772546447895372882827459834547848021995518823017403433176626179464043468453431329356999674750185826276525414823746816739834375514262888896130183978227663934602309833899393177170992328558820858...

output:

100101000011111110010010000000100111101000101100100001100011101101000110101001000010001010110000101100000010101011101011110110001101011110000101010001101001101010010000010001000010100001110110111110010000000011001111110111111101110000010001001111111010000001000101001110011011001100110000100000001011...

result:

ok single line: '100101000011111110010010000000...1000010011001101100111110110100'

Test #10:

score: 0
Accepted
time: 867ms
memory: 102136kb

input:

372274407543912221982191536561151601578958649016043451317550979954562101820786170731106344809290144718888123820074772096417411659245427254206197061850841133092863747075759085793436423279158306734547915730030610947165378479555799247014846123300384038895956562259452610490062532216259662749727823163857...

output:

110001001111101000010000100111100101001001110001100111101101011100110011111011100110110111100110010100000011100000110101110000011001111111011110001101000011111000011111111101010111110101000111101110110010010110011100011001011101010101000011000011001010011101110000101101101000100111100101001111101011...

result:

ok single line: '110001001111101000010000100111...0010110111100110010011000011110'

Test #11:

score: 0
Accepted
time: 863ms
memory: 102028kb

input:

316672063294425383394181975895561386308671311296764394390302497227130122522971704533830284752356759804763703140103600447061252053370582265841390296596762788767514019521233779768973800715569915323999438752400026453251001709818646402100527035644870200539869126933879532458328633496023756324178957350635...

output:

101001111000111010000000111111101001110010111000110001101010101000100100111100111101100111100010101001011110101000110101010101110101010010000111011110011111000110011000110011110101111001110100000010000110010010111111101000000001001000110001111110101011100001111010111000000101010110011100000110111101...

result:

ok single line: '101001111000111010000000111111...1111101100010001001010101000100'

Test #12:

score: 0
Accepted
time: 840ms
memory: 101988kb

input:

879518519042507751422740729478565367757277950214045528673080610285520525092284044348124842632597490341460216674479983206211648280352016324413239115677005617762915474175034765173031804967595088001606845151422592085950837029360083490539406567931691974471508503251624042388419904776978396992003945230605...

output:

111010001010111100101000110011010011111101011101111010001101000001001000100011010000011100001100001000111101011010111100001111001110011110010011111011000111000101100101000000101010101100111000011101101011010000000101010101010010001010110001001110111010001000010111011110100000001001101101110011011100...

result:

ok single line: '111010001010111100101000110011...0110101111010111110001010010111'

Test #13:

score: 0
Accepted
time: 923ms
memory: 102084kb

input:

202392545005864048931654484689036795907611014306843679919011237720722983687924412538800787500570060983451218266272245969145746833799102755625761397706621766054952283032255418833801705046782459669141755422809441025557373137918387390110137752940709206162085570995915719785325478161034424223932064739427...

output:

110101100010110111000100011111010101101001011010111110111101111011001000000110110110000001101010111001101000100000101100101110000100101000101001100010011011010110111100001100101100011110001011001100100011111001001101110101111011111111010001001001001100101101011000001100100001001001100100111010011111...

result:

ok single line: '110101100010110111000100011111...0010101100110011011010000101001'

Test #14:

score: 0
Accepted
time: 880ms
memory: 101988kb

input:

739759812496291305380781999367333382381025694695957725192051220435723469458058970932653293639089616186996838694475712794545530988474681738469945247100423307138636564944176563644503301199451683299183630054194256661633428570277799321353782037661738284115801314733551900286499827798966732563442893537594...

output:

110000111011010110111000010101111101010101000101001011111011111011000111010101100000011011100011101001001010011000010001101111001101100111010000001010011100011011011000000001111010110101000100001101111000100011100101101111011101101110110111110010110000011110101011001000101001101000000001111111111110...

result:

ok single line: '110000111011010110111000010101...1001000001111100000111100110110'

Test #15:

score: 0
Accepted
time: 881ms
memory: 102032kb

input:

998192477351161434627009008839145046429172094893296319413266418966308089884835830881064997461400552002904012240836364514005395206044461979019856734265952991891887329583982440051599957424228988338674122467702595810427326712356068176979412015877432368470541797753553177794427413156929452004426554171159...

output:

100001000000101001001011101111011000111011100001100110101110001010001010100110110100001101011101100110001110000101110001100001000101111100110100001010110101111110111010001001011101011010000011011111111111100011011101110010100100001101101000000100111010110110010010110111001101100001011001000111100000...

result:

ok single line: '100001000000101001001011101111...0011010001000101110110111010010'

Test #16:

score: 0
Accepted
time: 874ms
memory: 101976kb

input:

363677079582278220564564569729169264557086609147335917874585765415391093291438120113226059073763546089504217402195841356918915143586519866979721376884169170672431917854462565931109056184590682021952952373461876785373635407424380699578149920138346541316009693271180998654492596106655377534215027761259...

output:

110000000110110110000101101101000111101001010011110011001001011100111111001101101111101110011100111101011110111011111100101001000001011000011101110101111011010110100011100001110100101000100010110010000001111100001111100100101101111001100101100001100000001001110000011111110100110000001101001101101001...

result:

ok single line: '110000000110110110000101101101...0001011111110010100111000010110'

Test #17:

score: 0
Accepted
time: 900ms
memory: 101852kb

input:

821037799459097005998053291749135763018709513957643954879084679345683149084009409999543902429436984984806249229740335221821540730002059922211738051210892398302014894779237300893359640230341142220903852244381842834758545462537308974816609240546513001851762351260428916725930471192126887550930398259358...

output:

110110010011011001101111011000110111111011111100011001100111000010111011111010100000110111101111011000001001110101101000111011000010011010101001101101111001010010100110101000110111001010100101101101010110110110000011000111101100100111100011010011000001001001101001100011111001101111101011010011001111...

result:

ok single line: '110110010011011001101111011000...0100101011101110101101011011111'

Test #18:

score: 0
Accepted
time: 864ms
memory: 102132kb

input:

745410769137289067748266459981711511565398949483480163079318753345362262997628296569512070005465040431150263289640330752250655572492412803224812257924532908051729634300582950601332304843646708876695327017279861415434432565421041983177080277268495018300663894325207248359657952841882368070366571877744...

output:

110001010011010001110001010001101100011000111011100111111001111010100101011100011010100010111110101011100110001100111011011011011001101011010110010001111010010011111001001010001111011011000101100110110011100101001001010101000110101001111010101110010111011101010001111001011010101001010100000100100010...

result:

ok single line: '110001010011010001110001010001...1001111011110000111000111110101'

Test #19:

score: 0
Accepted
time: 857ms
memory: 101972kb

input:

151335267803275400770013022528615019744750773721565524715661313309563255131959484405561993360135622672171007469188766605234893116617632465747333351658870210747427019148068698322865748913932969705564372093489943340117242628767594143584829727091011976360664095940302912816879101794281622970931298866422...

output:

101000000010010111110000110100000100110111010011001011000111100001110000001100000000000110010010111011100000011110001110000110010111000001101101000010001011010001111111011111001000111111000111100110010001001110111111011100101111100101011000010111111100100010011001100100001000011110110001010000001000...

result:

ok single line: '101000000010010111110000110100...0000000100010011001111010101010'

Test #20:

score: 0
Accepted
time: 866ms
memory: 101988kb

input:

373568884951041237551823484071954623100314720777662911414296801440008116999428765805244828690432631336897490647602288901773336482727177012650054977980290252822588174463323652376176458546700726500311107384601735162185260288727652595620052948971952499839301776380639338903993402931243708805174906611060...

output:

110001011010100101101000001101101010011101010101011001000001111100100111101010101001000101101111001011101100000100000110110101110001110110010000000101111000110111011101100110010000100111001000110000111010001101101001000111011110101110000111000110011001111110101010001100110111010000111100111101100001...

result:

ok single line: '110001011010100101101000001101...0000000110001001001101001001101'

Test #21:

score: 0
Accepted
time: 881ms
memory: 101988kb

input:

481070760112777110006908305382193858642467795835275459484799014080221439037788167173758096603889358554367754167526879152512676197293309392768254634377463209876439288322682209055800507335367695706951840620371894865327415305232539441125961914859653396814900910757023023060406318466750176751601458904551...

output:

111111101000101011110111110110111001111000101010111101001100010100001110000010011101101100100101111101011010011110010010100111110100000101101001011111011111100110110101100011100001000110101111010011111110100110000011001110001111010001111001011001111001111111010110000000010111001101010101110111111000...

result:

ok single line: '111111101000101011110111110110...1000101011000001010001010001000'

Test #22:

score: 0
Accepted
time: 859ms
memory: 101852kb

input:

464664788497448698122205568005934753009694869080081794914795125689437063485050391439046475536532450812318830430062938247696066153047550233086365640224064835846361202067129139694856739308191711016968113450919663180682034598989480399066754780051068217097083865318783988295272778039974398486433918099482...

output:

111101011101110010110110101000001111000010000000100010010110011111000001010001100011010011001100100011111011010001011001100111111011100101111110101010111110110001101101001010110110101100001001111101101001011111011111101101111110001000100011011110010100111111100111011110001010010001010010111110001101...

result:

ok single line: '111101011101110010110110101000...1111001001010110011100001101110'

Test #23:

score: 0
Accepted
time: 857ms
memory: 101856kb

input:

550742510770063655839278268327723721043810520695612824662188040692990548361282153432567562427073960633655625398831923130984450789839635134955527666810869748401558920374504530094985861802280046246724183283733627829530360570565066223455868345810760599867486473107506631323291513453940314293275676618241...

output:

100100011011010000100100101110000110100000101000011010110011101100101101010101010010110000111000010101001101011111110100110101110000011011111010010000101010010010101110100010000101010010001100100000111000101010100011010100000001011101111100101111101000101011000111100001000010001100011111011111110010...

result:

ok single line: '100100011011010000100100101110...1101001001011011011001111000111'

Test #24:

score: 0
Accepted
time: 854ms
memory: 101984kb

input:

236940940077755145784386867561326809251731522966967201465607896997287477703853494272627842189443481918382228460339105939558871672590179396375633699565177887210617268655104610307528083600823248360556597849489976418077689251443166665748099549081394674921020274991798831554250607877269020019265264314255...

output:

111110101011110100110100100111000010100101011110011101010011111000110111100111011000001011000001001111001100011000100001010011101010010100100000011111110000110011110101110100101001000001100011001001011011110001001110100000111000110110000000111110000000111101001111111000011010110101110010011100001000...

result:

ok single line: '111110101011110100110100100111...1110011000001101001101001010011'

Test #25:

score: 0
Accepted
time: 873ms
memory: 102136kb

input:

417167357598807652794630874753199250901959000930066089539092674884033503996992553570639809797660944195749048871634991764644797912419757319596735022743762779209164879846845498130112318400445831514230887299594491093597370324317380212892274431304346990285080855292830646326605503735929791016901808401758...

output:

110111001011101011111110110101100010000010011100001010010001101110111110100011101010011111011110010111000101001101001111110011100101000101101111101100101111101000110000110011000001101101110111110101101101000010000011001111100110001100101111011011011101101101110001011010000111001010110000000010101100...

result:

ok single line: '110111001011101011111110110101...1010110000111011101101101100111'