結果
問題 | No.1097 Remainder Operation |
ユーザー | hedwig100 |
提出日時 | 2020-06-26 22:29:58 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 222 ms / 2,000 ms |
コード長 | 2,838 bytes |
コンパイル時間 | 1,460 ms |
コンパイル使用メモリ | 170,532 KB |
実行使用メモリ | 4,976 KB |
最終ジャッジ日時 | 2023-09-18 05:55:13 |
合計ジャッジ時間 | 6,032 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,504 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 2 ms
4,380 KB |
testcase_07 | AC | 23 ms
4,380 KB |
testcase_08 | AC | 22 ms
4,376 KB |
testcase_09 | AC | 21 ms
4,380 KB |
testcase_10 | AC | 22 ms
4,380 KB |
testcase_11 | AC | 22 ms
4,380 KB |
testcase_12 | AC | 215 ms
4,380 KB |
testcase_13 | AC | 215 ms
4,376 KB |
testcase_14 | AC | 215 ms
4,376 KB |
testcase_15 | AC | 217 ms
4,376 KB |
testcase_16 | AC | 216 ms
4,376 KB |
testcase_17 | AC | 222 ms
4,376 KB |
testcase_18 | AC | 200 ms
4,808 KB |
testcase_19 | AC | 202 ms
4,812 KB |
testcase_20 | AC | 204 ms
4,936 KB |
testcase_21 | AC | 199 ms
4,976 KB |
testcase_22 | AC | 204 ms
4,860 KB |
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内: main.cpp:75:20: 警告: ‘size_of_loop’ may be used uninitialized [-Wmaybe-uninitialized] 75 | ll before_loop,size_of_loop; | ^~~~~~~~~~~~ main.cpp:101:59: 警告: ‘before_loop’ may be used uninitialized [-Wmaybe-uninitialized] 101 | if (K%size_of_loop > 0) ans += Xs[before_loop + K%size_of_loop]; | ~~~~~~~~~~~~^~~~~~~~~~~~~~~~ main.cpp:75:8: 備考: ‘before_loop’ はここで定義されています 75 | ll before_loop,size_of_loop; | ^~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for (int i = 0; i < (n); 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; constexpr double EPS = 1e-4; constexpr double PI = 3.14159265358979; struct Debug { template<class T> static void print_value(T value,const char* name) { cout << name << ": " << value << '\n'; } template<class T> static void print_vector(vector<T> &vec,const char* name) { for (int i = 0;i < vec.size();++i) { cout << " " << name; printf("[%d]: ",i); cout << vec[i]; } cout << '\n'; } template<class T> static void print_2dvector(vector<vector<T>> &vec,const char* name) { for (int i = 0;i < vec.size();++i) { for (int j = 0;j < vec[i].size();++j) { cout << " " << name; printf("[%d][%d]: ",i,j); cout << vec[i][j]; } cout << '\n'; } } template<class T> static void print_set(set<T> &st,const char* name) { int i = 0; for (auto itr = st.begin();itr != st.end(); ++itr,++i) { cout << " " << name; printf("[%d]: ",i); cout << *itr; } cout << '\n'; } template<class T1,class T2> static void print_map(map<T1,T2> &mp,const char* name) { for (auto p: mp) { cout << " " << name << '[' << p.first << ']' << ": " << p.second; } cout << '\n'; } }; int main() { int N; cin >> N; vector<ll> A(N); rep(i,N) cin >> A[i]; ll X = 0; vector<ll> Xs; Xs.push_back(0); vector<bool> remainder(N + 1,false); remainder[0] = true; X = A[X]; while (!remainder[X%N]) { Xs.push_back(X); remainder[X%N] = true; X += A[X%N]; } Xs.push_back(X); //Debug::print_vector(Xs,"Xs"); ll before_loop,size_of_loop; for (int i = 0;i < Xs.size();++i) { if (Xs[i]%N == X%N) { before_loop = i; size_of_loop = Xs.size() - i - 1; break; } } for (ll i = before_loop + 1;i < Xs.size();++i) { Xs[i] -= Xs[before_loop]; } //Debug::print_vector(Xs,"Xs"); int Q; cin >> Q; int Xsize = Xs.size() - 1; rep(i,Q) { ll K; cin >> K; ll ans; if (K < before_loop) { ans = Xs[K]; } else { ans = Xs[before_loop]; K -= before_loop; ans += (ll)(K/size_of_loop) * Xs[Xsize]; if (K%size_of_loop > 0) ans += Xs[before_loop + K%size_of_loop]; } cout << ans << endl; } return 0; }