結果
問題 | No.1097 Remainder Operation |
ユーザー | hedwig100 |
提出日時 | 2020-08-16 11:51:21 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,682 bytes |
コンパイル時間 | 1,726 ms |
コンパイル使用メモリ | 174,436 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-11 10:26:29 |
合計ジャッジ時間 | 3,522 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
コンパイルメッセージ
main.cpp: In function 'int main()': main.cpp:58:17: warning: 'sumbefore' may be used uninitialized [-Wmaybe-uninitialized] 58 | ret += K/loop_size * sumloop; | ~~~~^~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:33:8: note: 'sumbefore' was declared here 33 | ll sumbefore,sumloop; | ^~~~~~~~~ main.cpp:58:32: warning: 'sumloop' may be used uninitialized [-Wmaybe-uninitialized] 58 | ret += K/loop_size * sumloop; | ~~~~~~~~~~~~^~~~~~~~~ main.cpp:33:18: note: 'sumloop' was declared here 33 | ll sumbefore,sumloop; | ^~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (int)(n); i ++) #define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i) using namespace std; using ll = long long; using PL = pair<ll,ll>; using P = pair<int,int>; constexpr int INF = 1000000000; constexpr long long HINF = 1000000000000000; constexpr long long MOD = 1000000007;// = 998244353; constexpr double EPS = 1e-4; constexpr double PI = 3.14159265358979; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; cin >> N; vector<ll> A(N); rep(i,N) cin >> A[i]; int now = 0; vector<int> visited(N,0); vector<int> route; while (visited[now] == 0) { visited[now] = 1; route.push_back(now); now = (now + A[now])%N; } vector<ll> before,loop; ll before_size,loop_size; ll sumbefore,sumloop; bool flag = false; rep(i,route.size()) { if (route[i] == now) flag = true; if (flag) { loop.push_back(A[route[i]]); sumloop += A[route[i]]; } else { before.push_back(A[route[i]]); sumbefore += A[route[i]]; } } before_size = before.size(); loop_size = loop.size(); rep(i,before_size - 1) before[i + 1] += before[i]; rep(i,loop_size - 1) loop[i + 1] += loop[i]; int Q; cin >> Q; rep(i,Q) { ll K; cin >> K; if (K <= before_size) cout << before[K - 1] << '\n'; else { ll ret = sumbefore; K -= before_size; ret += K/loop_size * sumloop; if (K%loop_size > 0) ret += loop[K%loop_size - 1]; cout << ret << '\n'; } } return 0; }