QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#402555 | #4274. $2x + 2$ | I_Love_Sonechka# | AC ✓ | 3ms | 4132kb | C++17 | 3.9kb | 2024-04-30 22:01:37 | 2024-04-30 22:01:38 |
Judging History
answer
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
// c++ short types
#define vt vector
typedef long long ll;
typedef long double ld;
void whattime() { cout << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; }
const ll inf = 1e18;
const int base = 1e9;
typedef vt<int> lnum;
void print(lnum a) {
printf ("%d", a.empty() ? 0 : a.back());
for (int i=(int)a.size()-2; i>=0; --i)
printf ("%09d", a[i]);
}
lnum read() {
string s; cin >> s;
lnum a;
for (int i=(int)s.length(); i>0; i-=9)
if (i < 9)
a.push_back (atoi (s.substr (0, i).c_str()));
else
a.push_back (atoi (s.substr (i-9, 9).c_str()));
return a;
}
void add(lnum &a, lnum b) {
int carry = 0;
for (size_t i=0; i<max(a.size(),b.size()) || carry; ++i) {
if (i == a.size())
a.push_back (0);
a[i] += carry + (i < b.size() ? b[i] : 0);
carry = a[i] >= base;
if (carry) a[i] -= base;
}
}
void subtract(lnum &a, lnum b) {
int carry = 0;
for (size_t i=0; i<b.size() || carry; ++i) {
a[i] -= carry + (i < b.size() ? b[i] : 0);
carry = a[i] < 0;
if (carry) a[i] += base;
}
while (a.size() > 1 && a.back() == 0)
a.pop_back();
}
void divide(lnum &a, int b) {
int carry = 0;
for (int i=(int)a.size()-1; i>=0; --i) {
long long cur = a[i] + carry * 1ll * base;
a[i] = int (cur / b);
carry = int (cur % b);
}
while (a.size() > 1 && a.back() == 0)
a.pop_back();
}
bool comp(lnum &a, int b) {
while (a.size() > 1 && a.back() == 0)
a.pop_back();
// ? a >= b
if(a.size() == 0) {
return b == 0;
} else if(a.size() == 1) {
return a[0] >= b;
}
return true;
}
bool comp(lnum &a, lnum &b) {
while (a.size() > 1 && a.back() == 0)
a.pop_back();
while (b.size() > 1 && b.back() == 0)
b.pop_back();
if(a.size() < b.size()) {
return false;
} else if(a.size() > b.size()) {
return true;
}
for(int i = a.size() - 1; i >= 0; --i) {
if(a[i] > b[i]) {
return true;
} else if(a[i] < b[i]) {
return false;
}
}
return true;
}
const int nmax = 1e6;
int a[nmax];
void precalc() {
vt<int> used(nmax);
for(int i = 1; i < nmax; ++i) {
int x = (i - 2) / 2;
used[i] = (x * 2 + 2 != i) || not used[x];
a[i] = a[i-1] + used[i];
}
}
lnum dumb(int n) {
return {a[n]};
}
lnum solve(lnum n) {
// lnum n = read();
if(n == vt<int>(1, 1)) {
// cout << "1\n";
return {1};
} else if(n == vt<int>(1, 2)) {
// cout << "2\n";
return {2};
} else if(n == vt<int>(1, 3)) {
// cout << "3\n";
return {3};
} else if(n == vt<int>(1, 4)) {
// cout << 3 << "\n";
return {3};
}
vt<lnum> cnt;
lnum value = n;
add(value, {2});
lnum power = {3};
for(int k = 0; k <= 5000; ++k) {
if(not comp(value, power)) {
// if(cnt.back() != vt<int>(1, 0)) {
// cnt.push_back({0});
// }
break;
}
lnum delta = value;
subtract(delta, power);
for(int z = 0; z <= k; ++z) {
divide(delta, 2);
}
cnt.push_back(delta);
add(power, power);
}
lnum res = {};
for(int i = cnt.size() - 1; i >= 0; --i) {
// print(cnt[i]);
// cout << "\n";
lnum delta = cnt[i];
if(i + 1 < cnt.size()) {
subtract(delta, cnt[i+1]);
} else {
add(delta, {+1});
}
for(int j = 1; j <= (i+2) / 2; ++j) {
add(res, delta);
}
}
{
value = n;
add(value, {2});
lnum power = {4};
for(int k = 0; k <= 5000; ++k) {
if(not comp(value, power)) {
// (k-1) / 2
add(res, {(k-1+2) / 2});
break;
}
add(power, power);
}
}
// print(res);
return res;
}
int main()
{
// print(solve({8}));
// return 0;
print(
solve(read())
);
return 0;
precalc();
for(int n = 1; n < nmax; ++n) {
if(solve({n}) != dumb({n})) {
cout << n << ":\n";
print(solve({n})); cout << "\n";
print(dumb({n})); cout << "\n";
exit(0);
}
}
// int tt = 1;
// for(int t = 0; t < tt; ++t) {
// solve();
// }
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3740kb
input:
4
output:
3
result:
ok answer is '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4084kb
input:
10000000000
output:
6666666667
result:
ok answer is '6666666667'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3720kb
input:
11537
output:
7692
result:
ok answer is '7692'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3716kb
input:
41309
output:
27540
result:
ok answer is '27540'
Test #5:
score: 0
Accepted
time: 3ms
memory: 3696kb
input:
8191927142339937565554845978095081242540169480073285738552305926582959325059543812213073905385467089
output:
5461284761559958377036563985396720828360112986715523825701537284388639550039695874808715936923644727
result:
ok answer is '546128476155995837703656398539...9550039695874808715936923644727'
Test #6:
score: 0
Accepted
time: 2ms
memory: 3820kb
input:
3442352750904517878505619138601923704219437640757539618101640600496556715434957688100692603387053285
output:
2294901833936345252337079425734615802812958427171693078734427066997704476956638458733795068924702192
result:
ok answer is '229490183393634525233707942573...4476956638458733795068924702192'
Test #7:
score: 0
Accepted
time: 3ms
memory: 3848kb
input:
1613323280652897219227411721866100145041476611268669226074320085219149805106782606494134047806758188
output:
1075548853768598146151607814577400096694317740845779484049546723479433203404521737662756031871172125
result:
ok answer is '107554885376859814615160781457...3203404521737662756031871172125'
Test #8:
score: 0
Accepted
time: 3ms
memory: 3744kb
input:
5315968240892751432719450950079352483724763602617515777985835699795112297723617975471814602589260139
output:
3543978827261834288479633966719568322483175735078343851990557133196741531815745316981209735059506756
result:
ok answer is '354397882726183428847963396671...1531815745316981209735059506756'
Test #9:
score: 0
Accepted
time: 2ms
memory: 3768kb
input:
4254525315983167363680527261349030702801865895012808546689914191512673794223422499077682440208603002
output:
2836350210655444909120351507566020468534577263341872364459942794341782529482281666051788293472401998
result:
ok answer is '283635021065544490912035150756...2529482281666051788293472401998'
Test #10:
score: 0
Accepted
time: 3ms
memory: 3756kb
input:
4232021319223122906781785255488524502328502739912063884613559438143045702320487112522484309917751092
output:
2821347546148748604521190170325683001552335159941375923075706292095363801546991408348322873278500728
result:
ok answer is '282134754614874860452119017032...3801546991408348322873278500728'
Test #11:
score: 0
Accepted
time: 3ms
memory: 4076kb
input:
1795624774898285292090286902750186163949672827604714746430754757406422760905150536380671234812971701
output:
1197083183265523528060191268500124109299781885069809830953836504937615173936767024253780823208647800
result:
ok answer is '119708318326552352806019126850...5173936767024253780823208647800'
Test #12:
score: 0
Accepted
time: 3ms
memory: 3748kb
input:
4822717262051522274281630372660419682967327262088834250036223458028953055139175905469830602157603781
output:
3215144841367681516187753581773613121978218174725889500024148972019302036759450603646553734771735852
result:
ok answer is '321514484136768151618775358177...2036759450603646553734771735852'
Test #13:
score: 0
Accepted
time: 3ms
memory: 4132kb
input:
2420522157427712177063212710553899155280648241917240982792673534179482218292455213946314991881868032
output:
1613681438285141451375475140369266103520432161278160655195115689452988145528303475964209994587912020
result:
ok answer is '161368143828514145137547514036...8145528303475964209994587912020'
Test #14:
score: 0
Accepted
time: 3ms
memory: 3824kb
input:
9609389761049001578964019340044768569257164534852566205215792890955388299397818366261838906610023430
output:
6406259840699334385976012893363179046171443023235044136810528593970258866265212244174559271073348955
result:
ok answer is '640625984069933438597601289336...8866265212244174559271073348955'
Test #15:
score: 0
Accepted
time: 3ms
memory: 3792kb
input:
7378100518154352784087117925119913114198069908998635745840877661112203325434672312431175562249252615
output:
4918733678769568522724745283413275409465379939332423830560585107408135550289781541620783708166168410
result:
ok answer is '491873367876956852272474528341...5550289781541620783708166168410'
Test #16:
score: 0
Accepted
time: 2ms
memory: 3744kb
input:
4314257129848969215611268956312124232769562015258259969302294181121144270721780102652371986908117553
output:
2876171419899312810407512637541416155179708010172173312868196120747429513814520068434914657938745033
result:
ok answer is '287617141989931281040751263754...9513814520068434914657938745033'
Test #17:
score: 0
Accepted
time: 0ms
memory: 3820kb
input:
7442513133020754007748287749235820140836485766563082482200516186848122640921515715527998921755861588
output:
4961675422013836005165525166157213427224323844375388321467010791232081760614343810351999281170574386
result:
ok answer is '496167542201383600516552516615...1760614343810351999281170574386'
Test #18:
score: 0
Accepted
time: 3ms
memory: 4048kb
input:
3461484012412528765843169791809202936903341569347941193333818142278082472445171817580403125597600451
output:
2307656008275019177228779861206135291268894379565294128889212094852054981630114545053602083731733632
result:
ok answer is '230765600827501917722877986120...4981630114545053602083731733632'
Test #19:
score: 0
Accepted
time: 3ms
memory: 4024kb
input:
1163272062750598620393469988307282589338426479894049959298993638249005296627594351977914826030081102
output:
775514708500399080262313325538188392892284319929366639532662425499336864418396234651943217353387402
result:
ok answer is '775514708500399080262313325538...6864418396234651943217353387402'
Test #20:
score: 0
Accepted
time: 3ms
memory: 3820kb
input:
4068560037015934876188912039122335004243864029335249206370283031741163876305460454503531769248201260
output:
2712373358010623250792608026081556669495909352890166137580188687827442584203640303002354512832134172
result:
ok answer is '271237335801062325079260802608...2584203640303002354512832134172'
Test #21:
score: 0
Accepted
time: 3ms
memory: 3740kb
input:
5565005101377395755496808721969606048354933767768901576729742263052044309300279715138209309197954425
output:
3710003400918263836997872481313070698903289178512601051153161508701362872866853143425472872798636284
result:
ok answer is '371000340091826383699787248131...2872866853143425472872798636284'
Test #22:
score: 0
Accepted
time: 3ms
memory: 4128kb
input:
5955281427312151598060753022957546231632661803019555928462527228479176277952673308710392524455774190
output:
3970187618208101065373835348638364154421774535346370618975018152319450851968448872473595016303849455
result:
ok answer is '397018761820810106537383534863...0851968448872473595016303849455'
Test #23:
score: 0
Accepted
time: 3ms
memory: 3824kb
input:
5999199660995226367587541425139665809699306237416367491756562600743005331872297761736053889864270206
output:
3999466440663484245058360950093110539799537491610911661171041733828670221248198507824035926576180135
result:
ok answer is '399946644066348424505836095009...0221248198507824035926576180135'
Test #24:
score: 0
Accepted
time: 1ms
memory: 4116kb
input:
2155514273756447121758927869937665552173017137262740529395979905843768743654327408778539354112687532
output:
1437009515837631414505951913291777034782011424841827019597319937229179162436218272519026236075125022
result:
ok answer is '143700951583763141450595191329...9162436218272519026236075125022'
Test #25:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
7588366615490051405430942621119859163585478194391436228387468801445509515856890540219070127651363167
output:
5058911076993367603620628414079906109056985462927624152258312534297006343904593693479380085100908777
result:
ok answer is '505891107699336760362062841407...6343904593693479380085100908777'
Test #26:
score: 0
Accepted
time: 3ms
memory: 3872kb
input:
3069119817864664964195356068892415035426862018367420612508577861775349962709346348512881925327625430
output:
2046079878576443309463570712594943356951241345578280408339051907850233308472897565675254616885083623
result:
ok answer is '204607987857644330946357071259...3308472897565675254616885083623'
Test #27:
score: 0
Accepted
time: 3ms
memory: 3740kb
input:
6088609027910777715746727861553568363088355582707685378247148205358342717518996505870051122255545321
output:
4059072685273851810497818574369045575392237055138456918831432136905561811679331003913367414837030215
result:
ok answer is '405907268527385181049781857436...1811679331003913367414837030215'
Test #28:
score: 0
Accepted
time: 3ms
memory: 3768kb
input:
7752395844202176560354506129946224949547707723163853784421446345689791536208995591077776340757462505
output:
5168263896134784373569670753297483299698471815442569189614297563793194357472663727385184227171641667
result:
ok answer is '516826389613478437356967075329...4357472663727385184227171641667'