結果
| 問題 |
No.1097 Remainder Operation
|
| コンテスト | |
| ユーザー |
kmjp
|
| 提出日時 | 2020-06-26 22:14:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 187 ms / 2,000 ms |
| コード長 | 1,180 bytes |
| コンパイル時間 | 2,263 ms |
| コンパイル使用メモリ | 195,728 KB |
| 最終ジャッジ日時 | 2025-01-11 11:39:34 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:43:17: warning: ‘fir’ may be used uninitialized [-Wmaybe-uninitialized]
43 | if(K>=fir) {
| ^~
main.cpp:28:12: note: ‘fir’ was declared here
28 | ll fir,per,dif;
| ^~~
main.cpp:28:16: warning: ‘per’ may be used uninitialized [-Wmaybe-uninitialized]
28 | ll fir,per,dif;
| ^~~
main.cpp:46:43: warning: ‘dif’ may be used uninitialized [-Wmaybe-uninitialized]
46 | cout<<V[fir+mo]+lp*dif<<endl;
| ~~^~~~
main.cpp:28:20: note: ‘dif’ was declared here
28 | ll fir,per,dif;
| ^~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
int N;
int A[101010];
int P[101010];
ll V[101010];
int Q;
ll K;
void solve() {
int i,j,k,l,r,x,y; string s;
cin>>N;
FOR(i,N) cin>>A[i];
MINUS(P);
P[0]=0;
ll fir,per,dif;
for(i=1;i<=N;i++) {
V[i]=V[i-1]+A[V[i-1]%N];
if(P[V[i]%N]==-1) {
P[V[i]%N]=i;
}
else {
fir=P[V[i]%N];
per=i-fir;
dif=V[i]-V[fir];
}
}
cin>>Q;
while(Q--) {
cin>>K;
if(K>=fir) {
ll lp=(K-fir)/per;
ll mo=(K-fir)%per;
cout<<V[fir+mo]+lp*dif<<endl;
}
else {
cout<<V[K]<<endl;
}
}
}
int main(int argc,char** argv){
string s;int i;
if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
cout.tie(0); solve(); return 0;
}
kmjp