結果

問題 No.1343 Dividing Digit
ユーザー cumincumin
提出日時 2021-01-16 13:38:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 14 ms / 2,000 ms
コード長 1,834 bytes
コンパイル時間 2,362 ms
コンパイル使用メモリ 167,324 KB
実行使用メモリ 4,712 KB
最終ジャッジ日時 2023-08-18 10:08:00
合計ジャッジ時間 2,840 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long
#define ld long double

#define rep(i, n) for(int i = 0; i < n; ++i)
#define rep2(i, a, b) for(int i = a; i <= b; ++i)
#define rrep(i, a, b) for(int i = a; i >= b; --i)

#define pii pair<int, int>
#define pll pair<ll, ll>

#define fi first
#define se second

#define pb push_back
#define eb emplace_back

#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi(a,b,c,d) vector<vector<int>> a(b,vector<int>(c,d));
#define vvll(a,b,c,d) vector<vector<ll>> a(b,vector<ll>(c,d));

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(c) ((ll)(c).size())

#define endl '\n'
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

//const int MOD = 1000000007;
//const int MOD = 998244353;
const ll INF = 1e18+1;
const int inf = 1e9+1;
const double PI = acos(-1);
int dx[8] = {1, 0, -1,  0,  1, 1, -1, -1};
int dy[8] = {0, 1,  0, -1, -1, 1,  1, -1};

bool range(int y, int x, int h, int w){
  if(y < 0 || x < 0 || y >= h || x >= w) return false;
  else return true;
}

const int MAX = 310000;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  cout << fixed << setprecision(10);
  
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  reverse(all(a));
  
  ll sum = 0;
  rep(i,n) sum += a[i]; 
  
  vector<ll> b(n+2);
  b[0] = 1;
  rep(i,n-1){
    b[i+1] = (b[i]*k)%sum;
  }
  ll ans = 0;
  rep(i,n){
    ans += a[i]*b[i];
    ans %= sum;
  }
  cout << ans%sum << endl;
  return 0;
}
0