CSES - Datatähti 2023 alku - Results
Submission details
Task:Kertoma
Sender:adex720
Submission time:2022-11-09 14:58:39 +0200
Language:Java
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.15 s1, 2, 3details
#2ACCEPTED0.16 s1, 2, 3details
#3ACCEPTED0.15 s1, 2, 3details
#40.20 s1, 2, 3details
#5ACCEPTED0.20 s1, 2, 3details
#6ACCEPTED0.19 s1, 2, 3details
#7ACCEPTED0.22 s2, 3details
#8ACCEPTED0.21 s2, 3details
#9ACCEPTED0.22 s2, 3details
#10ACCEPTED0.21 s2, 3details
#11--3details
#12--3details
#13--3details
#14--3details
#15--3details
#16--3details

Code

import java.math.BigInteger;
import java.util.Scanner;

public class C {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] numerotString = scanner.nextLine().split(" ");
        int[] numerot = new int[10];
        int yhteensa = 0;

        for (int i = 0; i < 10; i++) {
            numerot[i] = Integer.parseInt(numerotString[i]);
            yhteensa += numerot[i];
        }

        if (yhteensa <= 6) {
            System.out.print(pienempiKuin10(numerot));
            return;
        }

        int jaljella = numerot[0];
        int[] maarat = new int[8];
        int kerroin = 97656; // * 5n+1  8 kertaa,
        for (int i = 0; i < 8; i++) {
            int maara = (int) (jaljella / (double) kerroin);

            jaljella -= maara;
            maarat[7 - i] = maara;

            kerroin -= 1;
            kerroin *= 0.2;
        }

        int max = maarat[0] * 5; // Jos kaikki nollat olisivat luvun lopussa, tämä luku olisi

        int min = 10;
        int perus = (int) (max * 0.9f);
        while (true) {
            BigInteger kertoma = kertoma(new BigInteger(perus + ""));
            int pituus = kertoma.toString(10).length();

            int ero = pituus - yhteensa;
            if (ero == 0) {
                System.out.print(perus);
                return;
            } else if (ero > 0) {
                if (max == perus) break;
                max = perus;
            } else {
                if (min == perus) break;
                min = perus;
            }
            perus = min + (max - min) / 2;
        }


    }

    public static final BigInteger FACT_200 = new BigInteger("788657867364790503552363213932185062295135977687173263294742533244359449963403342920304284011984623904177212138919638830257642790242637105061926624952829931113462857270763317237396988943922445621451664240254033291864131227428294853277524242407573903240321257405579568660226031904170324062351700858796178922222789623703897374720000000000000000000000000000000000000000000000000");
    public static final BigInteger FACT_300 = new BigInteger("306057512216440636035370461297268629388588804173576999416776741259476533176716867465515291422477573349939147888701726368864263907759003154226842927906974559841225476930271954604008012215776252176854255965356903506788725264321896264299365204576448830388909753943489625436053225980776521270822437639449120128678675368305712293681943649956460498166450227716500185176546469340112226034729724066333258583506870150169794168850353752137554910289126407157154830282284937952636580145235233156936482233436799254594095276820608062232812387383880817049600000000000000000000000000000000000000000000000000000000000000000000000000");
    public static final BigInteger FACT_400 = new BigInteger("64034522846623895262347970319503005850702583026002959458684445942802397169186831436278478647463264676294350575035856810848298162883517435228961988646802997937341654150838162426461942352307046244325015114448670890662773914918117331955996440709549671345290477020322434911210797593280795101545372667251627877890009349763765710326350331533965349868386831339352024373788157786791506311858702618270169819740062983025308591298346162272304558339520759611505302236086810433297255194852674432232438669948422404232599805551610635942376961399231917134063858996537970147827206606320217379472010321356624613809077942304597360699567595836096158715129913822286578579549361617654480453222007825818400848436415591229454275384803558374518022675900061399560145595206127211192918105032491008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
    public static final BigInteger FACT_500 = new BigInteger("1220136825991110068701238785423046926253574342803192842192413588385845373153881997605496447502203281863013616477148203584163378722078177200480785205159329285477907571939330603772960859086270429174547882424912726344305670173270769461062802310452644218878789465754777149863494367781037644274033827365397471386477878495438489595537537990423241061271326984327745715546309977202781014561081188373709531016356324432987029563896628911658974769572087926928871281780070265174507768410719624390394322536422605234945850129918571501248706961568141625359056693423813008856249246891564126775654481886506593847951775360894005745238940335798476363944905313062323749066445048824665075946735862074637925184200459369692981022263971952597190945217823331756934581508552332820762820023402626907898342451712006207714640979456116127629145951237229913340169552363850942885592018727433795173014586357570828355780158735432768888680120399882384702151467605445407663535984174430480128938313896881639487469658817504506926365338175055478128640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
    public static final BigInteger FACT_600 = new BigInteger("12655723162254307425418678245150829297671403862274660768187828858528140823147351237817802795619571074765208532598060224803240903782164769430795025578054271906283387643826088448124626488332623608376164081221171179439885840257818732919037889603719186743943363062139593784473922231852782547619771723889252476871186000174697934549112845662596182308280390615184691924446215552586523740084932807259056238962104689731522587564412231618018774350801526839567367444928206231310973619440354723718012867753019556135721376207959558860559933052856914157120622980057169891912595926540427596853441276985006724869558201930657900240943007657817473684008944448183219124163017666607770667585082169598239230274035517738648065600492702095732843492708856036920219883363111527988109277392696562776813446645651238419301586157342867860646666350050113314787911320639668510871569846664873595017518995670958477806411667505346462590471136862647349666243426242677175204732314281064417939041868653741187423064985189556742640111598580035644021835576715752869397465453828584471291269955890393294448315746500268702149708808053100406398480942695623586049403348084970064668900206251516968479727515576425962392136269169089884609794271331061018895634421094082310408889752954265842691732460538911784960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
    public static final BigInteger FACT_700 = new BigInteger("2422040124750272179867875093812352218590983385729207299450679664929938160215647420444519051666484819249321456671497049842327525093874817343838393757631459228450828499972271274140160311057830558463636337124079332447820739281101037112665387537180790257577919273108262916904750405235055060084012219492892375635136296622020023178109619818046179906897450420548912610870589088056503913584562211037693288782960900195074130999799035970711436279339094292032866260496375825461427727555710003007752906141470639574390024988514914264449865006458873226951941899545970333910351588559232940829569276986080222200289966128343931630028789203382654749603473516314765262772257171154686716862814184728741187147936349501653197457455660413134506049122044947052623384682088864790673309569292384215611788014274954905914148362303226200246816441301934846080254998647325270606104512088058712293349862185399243309054299576381718806247238195232604642614329894070636163753672091232751612378348273840757873567717532879242518337119540602943609411629349009566043720836737401090882392975031224612531245642687296717053747734506443314924558119560479901478736209556925161517737110399754730551854066328420014728657896286936523787080206476327157136441318773432751007263108056958251693811280957243202460157111778617472683761623869704457588005158037495665069625778930898095725794710701639238231528115579619120287378689238934335198508665933917257143975277707590597511989345068701735940169672561864713107115016747368992690116082633762172346688969840862517264384000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
    public static final BigInteger FACT_750 = new BigInteger("258080348888515099592332164484462756339873138465439573430307783197416299243027155954177662782377988121786330241704205895696623863512136060073312399642903214981208677314332718179153141978050966912949044667285654509382893505742607320421138132489315975231024810455007561169027261467512016768219520949535523546245854587488300301587183831771306983230117702008541840588049868016262367530942050459679189959463016758263347175105682443459003758959420242420726446706871468610625180427774309822202013596386312335770257465620916795856541100240403653418300558044035800114916334162467899218825148943236293534338393691010564310549992850783040465739751374426786747138626367579170192142097000349188282966355601543364983866957807309071157224340301273138290328107224394242829508399720499754226069171146720700234961415691287653024650299449906791576444251896485737971148164303644519711822671071868913869053620498919344969212998198225423025504218155127792386786458610552302642301073848826614379519325627718818344197310234412241124626537898818059135881858620937671892189773976665326097756916365777800910711964674956323807152975316097362834398899617301975133152609071733317184179899830467924960162542548165522288593680830726827471269664435668435452031231830173305890851437975594409695453191272723171217148965163615764918779939588269561484233990603264734628306313494325446968691199021480680030775923198882305274863248464494464792535591126770493037747746544723130922945086462793250633576961329623263968229991681219729167736126795908539581595379671619786936503310162538854374487828471187674691932819466467181689212704982380869534574016124715756846188037238391662694608404480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
    public static final BigInteger FACT_800 = new BigInteger("771053011335386004144639397775028360595556401816010239163410994033970851827093069367090769795539033092647861224230677444659785152639745401480184653174909762504470638274259120173309701702610875092918816846985842150593623718603861642063078834117234098513725265045402523056575658860621238870412640219629971024686826624713383660963127048195572279707711688352620259869140994901287895747290410722496106151954257267396322405556727354786893725785838732404646243357335918597747405776328924775897564519583591354080898117023132762250714057271344110948164029940588827847780442314473200479525138318208302427727803133219305210952507605948994314345449325259594876385922128494560437296428386002940601874072732488897504223793518377180605441783116649708269946061380230531018291930510748665577803014523251797790388615033756544830374909440162270182952303329091720438210637097105616258387051884030288933650309756289188364568672104084185529365727646234588306683493594765274559497543759651733699820639731702116912963247441294200297800087061725868223880865243583365623482704395893652711840735418799773763054887588219943984673401051362280384187818611005035187862707840912942753454646054674870155072495767509778534059298038364204076299048072934501046255175378323008217670731649519955699084482330798811049166276249251326544312580289357812924825898217462848297648349400838815410152872456707653654424335818651136964880049831580548028614922852377435001511377656015730959254647171290930517340367287657007606177675483830521499707873449016844402390203746633086969747680671468541687265823637922007413849118593487710272883164905548707198762911703545119701275432473548172544699118836274377270607420652133092686282081777383674487881628800801928103015832821021286322120460874941697199487758769730544922012389694504960000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
    public static final BigInteger FACT_850 = new BigInteger("52434751522060149269696758009111366494594006149283971551118518704361064639661011262327769680210270052405196789850366740433480742081853431690138814839247096312393098508601663171386622962201449494651694232294447165511801941404582111464552094033017415943152746288180465697972482714766701591182776216378597637016012582764527433363037287892386862534832329869493630145056976279925089778568129223896723943726208653032142324034536572789642526321806670350536480306386368965235792938094052619043062279200034461909662659644715276464208734165308376421949092803856758485655002021778099766423867710367686546929824758686012182151711995787180451629947989146012205816113744470064708414219977196164631499964008000951850939258339564511891910398060268276013762043871926479512145831371595571110917409056832667807316192358533958394070679772271820021868191654916620301175626835768814020539849377076187957445596808496816129504158502747535865973794881108960340739390678450182138952905327009033144549204182944190726448908375315616103345436087995653045435599224049528612567535795030792844982897054580506057039993829915685767927629332533940347487616012667168803197548947801977835216402520738480065118183279127637818623686905610586664383329897386939013110789743070517678651885587725304904508610402304772153223711105259316121049496321865144282157818047120879216941256603813678497183544129044509039398293708587786560053731032875058158164051063451298070124761815230958358012143425773359913132522992524394805233859331492384358089563079776173145551412763094214205775261013470862322014291092347097789939426389853465446167342852384678371012511930619486647496230261195953669456479102957165888556952780345846999479870949287871472990737616334055901217768749339532363920138424388739881666970285291169557663861002810994628287424621939375705886304878648618320794176940303471192571537789575275611190961555723873917220621504066742556810645542400915375390720000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
    public static final BigInteger FACT_900 = new BigInteger("67526802209645841583879061361800814224269427869589384312198268703685091643180416969132446952698303794226010370578672908593198347699886928591906501031587651846976759681112609524787093848004428636186893395272784450630354080243217646658024696659065951793757223520229235577548653833681102170973893746054649126415909143150172860721156685810655759230011450132992176454983227538696340112610447029002337004887877266387704586077293585433151612518800147764461182680822867092786694982831838641800997499819339206579415325649748486265233918911087114592440896594062675914294925816719862178374679272092637524786939036290035924271782253738059886933923447877769583003016705363339031413069155837518524761078342052635475632113169618774549275701480106933362990003732589370593557325299434734459295866728988740794174654391479926000848846686708729736713207285203712732201272410830836913052635365082888725171636081587151603468291106754640398232146673627370895934090777828827549554232436190464827998683927179246029919443251026464452337939599198528297828591122689960620361238248313158071643395848405047261412680039877733761849874447323867911712630023171745968278465780558568067035013885275080292137360491875164947724464221693533755035300065350065137490832039523382963747026185653050331832380991844842560750923543775188582096487476950254418365198999674684417286265442786651594404781622946901879166382930714196908227460133027605817864877377712193142137625430353718448269390732615776645283198828602917680224041088993892610506802195917247838900106910698057030379190571057605849323113308634452008179881165616449767648354161225066967961297609698742737923389391615207441152319392845687673311899247085327703421862972871644495409572259985563215471482083325653231777113271326579970310755604973969708949477374254974480294652427022436705380184064008853457214518515270985563195412993145274057688634448812449445800617631162768243125606424844709372022149908463572254912654907763445758543980999149122998104378965626781898655221443263601405152073199706585080288735040205417371277253096243200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");
    public static final BigInteger FACT_950 = new BigInteger("1398482541782935643804076691560480889915998440155817289184424361471088554831945426769627793564422182417055106164687328968800337838015092091902426708062585754575758761840629101148022202088616791912489053482866845368492689362680348653796205483555373854592456218070694691705525740396798705940868646724824284207093151611109576110720548444329317710216110647877991896226422491521850828595540404858022075949677336135888382223667261520227307746590278225849364822818688836257463054227780939230451103538710215851987205677537048482160223572199279284117451224132373001283371301327748829720294520197304170767712014548861589250006845399476495213899063451656157650046959183486755881486521917991465353136174132572085159554294308742343997607375110074558336621161865669641233890984526944612898577907685789137489893983148709227096968737623566896040242263207335675963585922754508701637571117210471564252770570750986133957864067854642461333055446897356256150227759705161144342074998081690812845683437831834697577243723598629942007502158280264176806534264401532973204717702416909416881338635446682316115641175873267562660403190728153051309523731329937953128064805704669965310761454031007380577278555676647463602920304388801983631722813659620707911156485861041283361984654669874236982608585132243947301552513613611220015558453448924690739929122514945064605460031495266893341079448598602888778912070021944443316296980075190303839112675319752345427865151848929296445310091170773808682347150322723856486107805316543473255318746117468843202152153020851636933294448384581108333226009129599161980428471679024129941277718802294844225208011510362580468464079539685857597219536595114366720698051081028644017686258454536950017818406904897903310294734749680357539808121993820966632438607133926895767650158824385429998931170890049739411385071900802105888683110544033206102184261669482758401109754069003250076283022582711306994996277879328045961071730358543540500962142907125663566830842880290774899152437963716454512427624332124652969580549126054320287541325135782164668167493343515686764514235963736449314315122164198258363850671212708602703180299255302930935371174390553238003525108112573507911441672412518463779635200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");

    public static BigInteger kertoma(BigInteger luku) {
        int comp = luku.compareTo(FACT_200);
        if (luku.compareTo(BigInteger.ONE) == 0) {
            return luku;
        } else if (comp < 0) {
        } else if (comp == 0) {
            return luku.multiply(FACT_200);
        } else if (luku.compareTo(FACT_300) == 0) {
            return luku.multiply(FACT_300);
        } else if (luku.compareTo(FACT_400) == 0) {
            return luku.multiply(FACT_400);
        } else if (luku.compareTo(FACT_500) == 0) {
            return luku.multiply(FACT_500);
        } else if (luku.compareTo(FACT_600) == 0) {
            return luku.multiply(FACT_600);
        } else if (luku.compareTo(FACT_700) == 0) {
            return luku.multiply(FACT_700);
        } else if (luku.compareTo(FACT_750) == 0) {
            return luku.multiply(FACT_750);
        } else if (luku.compareTo(FACT_800) == 0) {
            return luku.multiply(FACT_800);
        } else if (luku.compareTo(FACT_850) == 0) {
            return luku.multiply(FACT_850);
        } else if (luku.compareTo(FACT_900) == 0) {
            return luku.multiply(FACT_900);
        } else if (luku.compareTo(FACT_950) == 0) {
            return luku.multiply(FACT_950);
        }

        return kertoma(luku.subtract(BigInteger.ONE)).multiply(luku);
    }

    public static int pienempiKuin10(int[] numerot) {
        if (numerot[2] == 1) { // 2 4 5 6 8 9

            if (numerot[0] == 1) { // 5 6 9
                if (numerot[1] == 1)
                    return 5;
                if (numerot[7] == 1)
                    return 6;
                return 9;
            } else { // 2 4 8
                if (numerot[4] == 0)
                    return 2;
                if (numerot[0] == 0)
                    return 4;
                return 8;
            }

        } else { // 1 3 7
            if (numerot[1] == 1)
                return 1;
            if (numerot[6] == 1)
                return 3;
            return 7;
        }
    }
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
0 0 1 0 0 0 0 0 0 0

correct output
2

user output
2

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
0 0 0 0 0 0 1 0 0 0

correct output
3

user output
3

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
0 0 1 0 1 0 0 0 0 0

correct output
4

user output
4

Test 4

Group: 1, 2, 3

Verdict:

input
2 0 1 1 0 0 1 0 2 0

correct output
10

user output
(empty)

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

input
9 3 1 1 2 2 3 1 6 1

correct output
27

user output
27

Test 6

Group: 1, 2, 3

Verdict: ACCEPTED

input
10 4 3 4 3 2 2 4 3 7

correct output
36

user output
36

Test 7

Group: 2, 3

Verdict: ACCEPTED

input
71 53 36 30 25 29 42 24 34 29

correct output
199

user output
199

Test 8

Group: 2, 3

Verdict: ACCEPTED

input
71 33 46 38 27 45 36 21 35 35

correct output
205

user output
205

Test 9

Group: 2, 3

Verdict: ACCEPTED

input
93 38 35 26 43 54 38 25 41 34

correct output
222

user output
222

Test 10

Group: 2, 3

Verdict: ACCEPTED

input
100 33 33 45 36 43 38 54 56 36

correct output
242

user output
242

Test 11

Group: 3

Verdict:

input
3419 1797 1845 1849 1879 1791 ...

correct output
5959

user output
(empty)

Test 12

Group: 3

Verdict:

input
4776 2695 2709 2781 2616 2753 ...

correct output
8391

user output
(empty)

Test 13

Group: 3

Verdict:

input
20097 12282 12229 12214 12406 ...

correct output
32001

user output
(empty)

Test 14

Group: 3

Verdict:

input
47934 29918 29878 29713 29984 ...

correct output
71718

user output
(empty)

Test 15

Group: 3

Verdict:

input
84691 54156 54277 54533 54296 ...

correct output
123123

user output
(empty)

Test 16

Group: 3

Verdict:

input
99098 63339 63878 64182 63904 ...

correct output
142663

user output
(empty)