結果
問題 | No.1150 シュークリームゲーム(Easy) |
ユーザー |
|
提出日時 | 2020-10-08 02:40:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 46 ms / 2,000 ms |
コード長 | 1,222 bytes |
コンパイル時間 | 575 ms |
コンパイル使用メモリ | 69,504 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-20 05:39:53 |
合計ジャッジ時間 | 3,815 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 43 |
コンパイルメッセージ
main.cpp:6:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 6 | main() | ^~~~ main.cpp: In function 'int main()': main.cpp:76:27: warning: 'X' may be used uninitialized [-Wmaybe-uninitialized] 76 | ans+=max(X-x,x-X); | ~^~ main.cpp:45:23: note: 'X' was declared here 45 | int x,X; | ^ main.cpp:76:27: warning: 'x' may be used uninitialized [-Wmaybe-uninitialized] 76 | ans+=max(X-x,x-X); | ~^~ main.cpp:45:21: note: 'x' was declared here 45 | int x,X; | ^
ソースコード
#include<iostream>#include<algorithm>using namespace std;int N;long A[1<<17];main(){cin>>N;int s,t;cin>>s>>t;s--,t--;for(int i=0;i<N;i++)cin>>A[i];int L=abs(t-s)-1,R=N-L-2;long ans=A[s]-A[t];if(L%2+R%2<=1){if(s<t){for(int i=1;i<=L;i++){if(i*2<=L+1)ans+=A[s+i];else ans-=A[s+i];}for(int i=1;i<=R;i++){if(i*2<=R+1)ans+=A[(s+N-i)%N];else ans-=A[(s+N-i)%N];}}else{for(int i=1;i<=L;i++){if(i*2<=L)ans-=A[t+i];else ans+=A[t+i];}for(int i=1;i<=R;i++){if(i*2<=R)ans-=A[(t+N-i)%N];else ans+=A[(t+N-i)%N];}}}else{int x,X;if(s<t){for(int i=1;i<=L;i++){if(i*2<=L)ans+=A[s+i];else if(i*2==L+1)x=A[s+i];else ans-=A[s+i];}for(int i=1;i<=R;i++){if(i*2<=R)ans+=A[(s+N-i)%N];else if(i*2==R+1)X=A[(s+N-i)%N];else ans-=A[(s+N-i)%N];}}else{for(int i=1;i<=L;i++){if(i*2<=L)ans-=A[t+i];else if(i*2==L+1)x=A[t+i];else ans+=A[t+i];}for(int i=1;i<=R;i++){if(i*2<=R)ans-=A[(t+N-i)%N];else if(i*2==R+1)X=A[(t+N-i)%N];else ans+=A[(t+N-i)%N];}}ans+=max(X-x,x-X);}cout<<ans<<endl;}