結果
| 問題 | No.1097 Remainder Operation |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-08 17:29:52 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 23 ms / 2,000 ms |
| + 645µs | |
| コード長 | 1,205 bytes |
| 記録 | |
| コンパイル時間 | 2,773 ms |
| コンパイル使用メモリ | 354,352 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-10-08 17:30:03 |
| 合計ジャッジ時間 | 6,280 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
ソースコード
// WRONG #8 (PREFIX_INT): prefix sums and cycle sum are stored in 32-bit int.
// Input: T, then T cases of (N / A / Q / K_1..K_Q).
// Fails when (tail + one cycle) sum exceeds 2^31-1 (big A, long path).
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static void solve() {
int n; scanf("%d", &n);
vector<ll> a(n);
for (auto &x : a) scanf("%lld", &x);
vector<int> seen(n, -1);
vector<int> pre(1, 0); // BUG: should be long long
int r = 0, steps = 0;
while (seen[r] == -1) {
seen[r] = steps;
pre.push_back(pre.back() + (int)a[r]); // overflows past 2^31-1
steps++;
r = pre[steps] % n; // overflowed value -> wrong/negative index
}
int mu = seen[r], lam = steps - mu;
int S = pre[steps] - pre[mu]; // BUG: cycle sum in int
int q; scanf("%d", &q);
while (q--) {
ll k; scanf("%lld", &k);
if (k <= steps) { printf("%lld\n", (ll)pre[k]); continue; }
ll t = k - mu, full = t / lam, rem = t % lam;
ll ans = (ll)pre[mu] + full * (ll)S + (ll)(pre[mu + rem] - pre[mu]);
printf("%lld\n", ans);
}
}
int main() {
solve();
}