結果

問題 No.16 累乗の加算
ユーザー DialBirdDialBird
提出日時 2016-12-16 21:12:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 293 ms / 5,000 ms
コード長 716 bytes
コンパイル時間 460 ms
コンパイル使用メモリ 62,592 KB
実行使用メモリ 6,908 KB
最終ジャッジ日時 2023-09-08 12:04:37
合計ジャッジ時間 3,088 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,708 KB
testcase_01 AC 4 ms
6,780 KB
testcase_02 AC 293 ms
6,872 KB
testcase_03 AC 76 ms
6,800 KB
testcase_04 AC 86 ms
6,692 KB
testcase_05 AC 96 ms
6,844 KB
testcase_06 AC 192 ms
6,844 KB
testcase_07 AC 136 ms
6,816 KB
testcase_08 AC 207 ms
6,844 KB
testcase_09 AC 223 ms
6,908 KB
testcase_10 AC 176 ms
6,744 KB
testcase_11 AC 9 ms
6,788 KB
testcase_12 AC 177 ms
6,700 KB
testcase_13 AC 88 ms
6,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

#define REP(i,first,last) for (int i=first;i<last;i++)
#define FOR(it,con) for (auto it=con.begin();it!=con.end();it++)

const int devider = 1000002;
int x,N;
vector<int> amari_list(devider, -1);

int main(){
  cin >> x;
  cin >> N;
  int val;
  long result = 0;
  REP(i,0,N) {
    cin >> val;
    int target = val % devider;

    if (amari_list[target] == -1) {
      int amari = 1;
      REP(j,0,target){
        amari *= x;
        amari %= (devider+1);
      } 
      amari_list[target] = amari;
    }
    result += amari_list[target];
    result %= (devider+1);
  }

  cout << (result % (devider + 1)) << endl;
}
0