結果

問題 No.933 おまわりさんこいつです
ユーザー noisy_noiminnoisy_noimin
提出日時 2019-11-29 22:52:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,017 bytes
コンパイル時間 861 ms
コンパイル使用メモリ 100,276 KB
実行使用メモリ 11,148 KB
最終ジャッジ日時 2024-05-01 00:41:35
合計ジャッジ時間 6,007 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 7 ms
6,944 KB
testcase_12 AC 20 ms
6,940 KB
testcase_13 AC 425 ms
6,940 KB
testcase_14 AC 892 ms
6,944 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}
};

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] / 10;
                z[j+i] %= 10;
            } else {
                z.push_back(x[i] * y[j] + carry);
                carry = z.back() / 10;
                z.back() %= 10;
            }
        }
        while(carry) {
            z.push_back(carry % 10);
            carry /= 10;
        }
    }
    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) digit_sum += mul[i];
    while(digit_sum >= 10) {
        digit_sum = calc_digit_sum(digit_sum);
    }

    cout << digit_sum << endl;
}
0