結果
| 問題 |
No.1097 Remainder Operation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-26 22:29:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 225 ms / 2,000 ms |
| コード長 | 2,838 bytes |
| コンパイル時間 | 1,507 ms |
| コンパイル使用メモリ | 174,348 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-04 22:14:29 |
| 合計ジャッジ時間 | 5,787 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:75:20: warning: 'size_of_loop' may be used uninitialized [-Wmaybe-uninitialized]
75 | ll before_loop,size_of_loop;
| ^~~~~~~~~~~~
main.cpp:101:59: warning: '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: note: 'before_loop' was declared here
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;
}