Cod sursa(job #2453820)

Utilizator bluestorm57Vasile T bluestorm57 Data 6 septembrie 2019 10:24:58
Problema Patrate2 Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.74 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("patrate2.in");
ofstream g("patrate2.out");

const int NMAX = 10000005;
long long n,ans[NMAX],sz = 1;

int main(){
    long long i,nconst,integer,j,newsz,part,units;
    f >> n;
    ans[1] = 1;
    nconst = n - 1;
    if(nconst)
        for(i = 1 ; i <= n ; i++){
            //ans = ans * 2 * (n - i + 1) * 2 * nconst;
            newsz = sz;
            for(j = 1 ; j <= sz ; j++){
                ans[j] *= 4;
                ans[j] *= (n - i + 1);
                ans[j] *= nconst;
                part = NMAX - 5;
                units = 7;
                while(ans[j] > 9){
                    integer = ans[j] / part;
                    ans[j] %= part;
                    ans[j + units] += integer;
                    if(integer)
                        newsz = max(newsz, j + units);
                    part /= 10;
                    units--;
                }
            }
            sz = newsz;
        }
    else
        for(i = 1 ; i <= n ; i++){
            //ans = ans * 2 * (n - i + 1) * 2 * nconst;
            newsz = sz;
            for(j = 1 ; j <= sz ; j++){
                ans[j] *= 2;
                ans[j] *= (n - i + 1);
                part = 10000000;
                units = 7;
                while(ans[j] > 9){
                    integer = ans[j] / part;
                    ans[j] %= part;
                    ans[j + units] += integer;
                    if(integer)
                        newsz = max(newsz, j + units);
                    part /= 10;
                    units--;
                }
            }
            sz = newsz;
        }
    for(i = sz; i ; i--)
        g << ans[i] ;

    return 0;
}