結果

問題 No.219 巨大数の概算
ユーザー nanophoto12nanophoto12
提出日時 2016-01-04 00:59:16
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 29 ms / 1,500 ms
コード長 2,565 bytes
コンパイル時間 528 ms
コンパイル使用メモリ 76,560 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-25 15:01:31
合計ジャッジ時間 4,951 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
4,380 KB
testcase_01 AC 29 ms
4,376 KB
testcase_02 AC 29 ms
4,376 KB
testcase_03 AC 29 ms
4,380 KB
testcase_04 AC 26 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 29 ms
4,380 KB
testcase_11 AC 29 ms
4,376 KB
testcase_12 AC 28 ms
4,376 KB
testcase_13 AC 29 ms
4,380 KB
testcase_14 AC 29 ms
4,376 KB
testcase_15 AC 29 ms
4,376 KB
testcase_16 AC 28 ms
4,380 KB
testcase_17 AC 29 ms
4,376 KB
testcase_18 AC 29 ms
4,380 KB
testcase_19 AC 29 ms
4,376 KB
testcase_20 AC 29 ms
4,380 KB
testcase_21 AC 29 ms
4,376 KB
testcase_22 AC 29 ms
4,376 KB
testcase_23 AC 29 ms
4,376 KB
testcase_24 AC 29 ms
4,376 KB
testcase_25 AC 29 ms
4,376 KB
testcase_26 AC 29 ms
4,380 KB
testcase_27 AC 29 ms
4,376 KB
testcase_28 AC 29 ms
4,380 KB
testcase_29 AC 29 ms
4,376 KB
testcase_30 AC 29 ms
4,384 KB
testcase_31 AC 28 ms
4,376 KB
testcase_32 AC 29 ms
4,380 KB
testcase_33 AC 29 ms
4,380 KB
testcase_34 AC 29 ms
4,380 KB
testcase_35 AC 28 ms
4,376 KB
testcase_36 AC 29 ms
4,380 KB
testcase_37 AC 29 ms
4,380 KB
testcase_38 AC 29 ms
4,380 KB
testcase_39 AC 29 ms
4,380 KB
testcase_40 AC 28 ms
4,384 KB
testcase_41 AC 29 ms
4,380 KB
testcase_42 AC 29 ms
4,380 KB
testcase_43 AC 29 ms
4,376 KB
testcase_44 AC 29 ms
4,376 KB
testcase_45 AC 29 ms
4,380 KB
testcase_46 AC 29 ms
4,376 KB
testcase_47 AC 28 ms
4,376 KB
testcase_48 AC 29 ms
4,376 KB
testcase_49 AC 29 ms
4,376 KB
testcase_50 AC 29 ms
4,380 KB
testcase_51 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define FOR(x,y) for(int x = 0;x < (y);x++)
#define LLI long long int
#define FORR(x,arr) for(auto& x:arr)
#define ALL(a) (a.begin()),(a.end())

#define _L(x) cout<<(x)<<endl
//#define _L(x) ;

template<int um> class UF {
public:
    vector<int> _parent,_rank;
    UF()
    {
        _parent=_rank=vector<int>(um,0);
        for(int i=0;i<um;i++)
        {
            _parent[i]=i;
        }
    }
    
    int Find(int x)
    {
        if(_parent[x] == x)
        {
            return x;
        }
        _parent[x] = Find(_parent[x]);
        return _parent[x];
    }
    
    int Union(int x,int y)
    {
        int xRoot = Find(x);
        int yRoot = Find(y);
        if(_rank[xRoot]>_rank[yRoot])
        {
            _parent[xRoot] = yRoot;
           return yRoot;
        }
        if(_rank[xRoot]<_rank[yRoot])
        {
            _parent[yRoot] = xRoot;
            return xRoot;
        }
        if(xRoot != yRoot)
        {
            _parent[yRoot] = xRoot;
            _rank[xRoot]++;
            return xRoot;
        }
        return xRoot;
    }
};

int N;

struct LargeValue
{
    double C;
    LLI D;

    LargeValue multiply(const LargeValue& other)
    {
        double nextC = C * other.C;
        if(nextC >= 10)
        {
            return {nextC / 10.0, D + other.D + 1};
        }
        return {nextC, D + other.D};
    }
    
    void Export()
    {
        int a = (int)C;
        int b = (int)(C*10) % 10;
        cout << a << " " << b << " " << D << endl;
    }
};


vector<LLI> A(10001);
vector<LLI> B(10001);

LargeValue ToLargeValue(LLI a)
{
    LLI digit = 0;
    double d = a;
    while(d >= 100)
    {
        digit++;
        d /= 10;
    }
    if(d >= 10)
    {
        return {(double)d/10.0, digit+1};
    }
    return {(double)d, digit};
}

LargeValue calculate(LLI a, LLI b)
{
    auto copyB = b;
    LargeValue seed = ToLargeValue(a);
    LargeValue source = {1.0, 0L};
    while(copyB > 0)
    {
        if((copyB & 1) == 1)
        {
            source = source.multiply(seed);
        }
        copyB >>= 1;
        seed = seed.multiply(seed);
    }
    return source;
}

int main() {

    cin >> N;
    
    FOR(i, N)
    {
        cin >> A[i];
        cin >> B[i];
    }
    FOR(i, N)
    {
        LargeValue result = calculate(A[i], B[i]);
        result.Export();
    }
    return 0;
}
0