結果

問題 No.1343 Dividing Digit
ユーザー oliverx3oliverx3
提出日時 2021-01-16 13:12:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 818 bytes
コンパイル時間 4,529 ms
コンパイル使用メモリ 226,384 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 09:20:49
合計ジャッジ時間 5,951 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 54 ms
4,376 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 15 ms
4,380 KB
testcase_06 AC 10 ms
4,380 KB
testcase_07 AC 21 ms
4,376 KB
testcase_08 AC 43 ms
4,376 KB
testcase_09 AC 48 ms
4,376 KB
testcase_10 AC 8 ms
4,380 KB
testcase_11 AC 19 ms
4,376 KB
testcase_12 AC 39 ms
4,380 KB
testcase_13 AC 36 ms
4,376 KB
testcase_14 AC 7 ms
4,380 KB
testcase_15 AC 18 ms
4,376 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 48 ms
4,380 KB
testcase_18 AC 53 ms
4,376 KB
testcase_19 AC 35 ms
4,380 KB
testcase_20 AC 25 ms
4,376 KB
testcase_21 AC 45 ms
4,380 KB
testcase_22 AC 46 ms
4,376 KB
testcase_23 AC 58 ms
4,380 KB
testcase_24 AC 48 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#if __has_include(<atcoder/all>)
#include<atcoder/all>
#endif
// using namespace std;
// using namespace atcoder;
#define int long long
#define rep(i, n) for(int i = 0;i<(int)(n);i++)
#define all(v) (v).begin(),(v).end()
using lint = long long;
using ll = long long;
using P = std::pair<int,int>;

int mod_pow(int n,int k,int mod) {
    int res = 1;
    while(k) {
        if(k&1) res*=n,res%=mod;
        n*=n,n%=mod;
        k>>=1;
    }
    return res;
}

signed main(void) {
    int n,k;
    std::cin >> n >> k;
    int mod = 0;
    std::vector<int> v(n);
    rep(i, n) std::cin >> v[i],mod+=v[i];
    int sum = 0;
    std::reverse(all(v));
    rep(i, n) {
        if(!i&&!v[i]) continue;
        sum+=v[i]*mod_pow(k,i,mod),sum%=mod;
    }
    std::cout << sum << std::endl;
    return 0;
}
0