結果
| 問題 | No.1097 Remainder Operation |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-26 22:36:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 440 ms / 2,000 ms |
| コード長 | 1,012 bytes |
| 記録 | |
| コンパイル時間 | 1,580 ms |
| コンパイル使用メモリ | 171,900 KB |
| 実行使用メモリ | 75,292 KB |
| 最終ジャッジ日時 | 2024-07-04 22:22:28 |
| 合計ジャッジ時間 | 7,553 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';
const int mx=200010;
const ll mod=1e9+7;
int main(){
int n;
cin >> n;
vector<vector<ll>> add(45, vector<ll>(n,0));
vector<vector<ll>> nxt(45, vector<ll>(n,0));
rep(i,n){
cin >> add[0][i];
}
rep(i,n){
nxt[0][i] = (i+add[0][i])%n;
}
int q; cin >> q;
rep(j,43){
auto nx = nxt[j];
auto ad = add[j];
rep(i,n){
nxt[j+1][i] = nx[nx[i]];
add[j+1][i] = ad[i] + ad[nx[i]];
}
}
while(q--){
ll k; cin >> k;
ll ans = 0;
int pos = 0;
int cnt = 0;
while(k>0){
if(k%2==1){
ans += add[cnt][pos];
pos = nxt[cnt][pos];
}
cnt++;
k/=2;
}
cout << ans << ln;
}
return 0;
}