結果

問題 No.1343 Dividing Digit
ユーザー Sooh317Sooh317
提出日時 2021-01-16 13:05:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 2,098 bytes
コンパイル時間 1,960 ms
コンパイル使用メモリ 200,288 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 09:08:58
合計ジャッジ時間 3,207 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
//#include <atcoder/modint>
//using namespace atcoder;
//using mint = modint998244353;
//using mint = modint1000000007;
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cerr << endl;int cnt = 0;for(const auto& v : vv){cerr << cnt << "th : "; view(v); cnt++;} cerr << endl;}
#pragma endregion
using ll = long long;
const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001ll; 
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
template<class T, class K>bool chmax(T &a, const K b) { if (a<b) { a=b; return 1; } return 0; }
template<class T, class K>bool chmin(T &a, const K b) { if (b<a) { a=b; return 1; } return 0; }
ll rudiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } //  20 / 3 == 7
ll rddiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // -20 / 3 == -7
ll power(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a;} a = a * a; p >>= 1;} return ret;}
ll modpow(ll a, ll p, ll m){ll ret = 1; while(p){if(p & 1){ret = ret * a % m;} a = a * a % m; p >>= 1;} return ret;}
/*---------------------------------------------------------------------------------------------------------------------------------*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    ll m = accumulate(a.begin(), a.end(), 0ll);
    ll cnt = 1, ans = 0;
    for(int i = n - 1; i >= 0; i--){
        ans += cnt * a[i] % m;
        if(ans >= m) ans -= m;
        cnt = cnt * k % m;
    }
    cout << ans << endl;
}       
/*
   * review you code when you get WA (typo? index?)
   * int overflow, array bounds
   * special cases (n=1?)
*/
0