結果
問題 | No.1097 Remainder Operation |
ユーザー | totori_nyaa |
提出日時 | 2020-06-26 21:43:38 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 39 ms / 2,000 ms |
コード長 | 1,334 bytes |
コンパイル時間 | 2,341 ms |
コンパイル使用メモリ | 198,520 KB |
実行使用メモリ | 5,588 KB |
最終ジャッジ日時 | 2023-09-18 03:48:49 |
合計ジャッジ時間 | 5,003 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,380 KB |
testcase_07 | AC | 5 ms
4,376 KB |
testcase_08 | AC | 5 ms
4,376 KB |
testcase_09 | AC | 5 ms
4,380 KB |
testcase_10 | AC | 5 ms
4,380 KB |
testcase_11 | AC | 5 ms
4,380 KB |
testcase_12 | AC | 38 ms
5,396 KB |
testcase_13 | AC | 38 ms
5,588 KB |
testcase_14 | AC | 37 ms
5,292 KB |
testcase_15 | AC | 37 ms
5,308 KB |
testcase_16 | AC | 38 ms
5,512 KB |
testcase_17 | AC | 39 ms
5,292 KB |
testcase_18 | AC | 34 ms
5,340 KB |
testcase_19 | AC | 35 ms
5,472 KB |
testcase_20 | AC | 35 ms
5,356 KB |
testcase_21 | AC | 35 ms
5,304 KB |
testcase_22 | AC | 36 ms
5,356 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;} template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;} int dx[4]={0,1,-1,0}; int dy[4]={1,0,0,-1}; long double eps = 1e-6; long double pi = acos(-1); signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); ll n; cin>>n; ll a[n]; for(int i=0;i<n;i++){ cin>>a[i]; } ll cnt[n+2]={}; cnt[0] = 0; ll now = 0; int r = 0; int used[n+2]={}; used[0] = 1; ll cy = -1; ll st = -1; int las = 0; for(int i=1;i<=n;i++){ now += a[r]; r = (r+a[r])%n; if(used[r]){ st = used[r]-1; cy = i+1 - used[r]; cnt[i] = now; las = i; break; } used[r] = i+1; cnt[i] = now; } int q; cin>>q; while(q--){ ll k; cin>>k; if(k <= st){ cout << cnt[k] << "\n"; continue; } ll ans = cnt[st]; k -= st; ans += (cnt[las] - cnt[st]) * (k/cy); k %= cy; ans += cnt[st+k] - cnt[st]; cout << ans << "\n"; } cerr << 61919700120 << endl; }