結果

問題 No.933 おまわりさんこいつです
ユーザー noisy_noiminnoisy_noimin
提出日時 2019-11-29 22:56:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,147 bytes
コンパイル時間 1,090 ms
コンパイル使用メモリ 97,260 KB
実行使用メモリ 8,912 KB
最終ジャッジ日時 2023-08-13 06:48:21
合計ジャッジ時間 6,008 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,760 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 16 ms
4,380 KB
testcase_13 AC 342 ms
4,380 KB
testcase_14 AC 716 ms
4,384 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};
constexpr ll BASE = ll(1e10);   

vector<ll> to_vec(ll n) {
    vector<ll> v;
    while(n) {
        v.push_back(n % 10);
        n /= 10;
    }
    return v;
}

vector<ll> product(vector<ll> &x, vector<ll> &y) {  // z = x * y;
    int n = x.size();
    int m = y.size();
    vector<ll> z;
    for(int j=0;j<m;++j) {
        int carry = 0;
        for(int i=0;i<n;++i) {
            if(j+i < z.size()) {
                z[j+i] += x[i] * y[j] + carry;
                carry = z[j+i] / BASE;
                z[j+i] %= BASE;
            } else {
                z.push_back(x[i] * y[j] + carry);
                carry = z.back() / BASE;
                z.back() %= BASE;
            }
        }
        while(carry) {
            z.push_back(carry % BASE);
            carry /= BASE;
        }
    }
    return z;
}

ll calc_digit_sum(ll n) {
    ll ret = 0LL;
    while(n) {
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    ll p;
    cin >> p;
    vector<ll> mul = to_vec(p);
    for(int i=1;i<n;++i) {
        cin >> p;
        vector<ll> v = to_vec(p);
        mul = product(mul, v);
        // for(int j=mul.size()-1;j>=0;--j) cerr << mul[j];
        // cerr << endl;
    }

    ll digit_sum = 0LL;
    for(int i=0;i<mul.size();++i) {
        while(mul[i]) {
            digit_sum += mul[i] % 10;
            mul[i] /= 10;
        }
    }
    while(digit_sum >= 10) {
        digit_sum = calc_digit_sum(digit_sum);
    }

    cout << digit_sum << endl;
}
0