結果
問題 | No.1097 Remainder Operation |
ユーザー |
![]() |
提出日時 | 2020-06-26 22:00:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 933 bytes |
コンパイル時間 | 929 ms |
コンパイル使用メモリ | 93,276 KB |
最終ジャッジ日時 | 2025-01-11 11:27:45 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 21 |
ソースコード
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <cstring> #include <cmath> using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> p(n, -1); vector<ll> b(n); ll x = 0, y; int f, g; for (int k = 0;; k++) { int i = x % n; if (p[i] >= 0) { f = k - p[i]; g = p[i]; break; } p[i] = k; b[k] = x; x += a[i]; } y = x - b[g]; int q; cin >> q; while (q--) { ll k; cin >> k; ll r; if (k < g) { r = b[k]; } else { k -= g; r = b[g + k % f] + y * (k / f); } cout << r << '\n'; } return 0; }