結果
問題 | No.770 Median Sequence |
ユーザー |
![]() |
提出日時 | 2018-11-21 21:13:37 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 348 ms / 2,000 ms |
コード長 | 654 bytes |
コンパイル時間 | 673 ms |
コンパイル使用メモリ | 65,720 KB |
実行使用メモリ | 44,032 KB |
最終ジャッジ日時 | 2024-12-24 16:06:17 |
合計ジャッジ時間 | 3,385 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 20 |
ソースコード
#include <iostream> #include <queue> using namespace std; typedef long long ll; const ll mod=1e9+7,M=3005; ll N,a[M],b[M],s[M],res=0; queue<ll> q[M]; int main(){ cin>>N; for(int i=0;i<N-1;i++) for(int j=0;j<N-i-1;j++) q[i].push(j==N-i-2); a[N-1]++; fill(s,s+N,1); for(int i=1;i<N;i++){ fill(b,b+N,0); ll S=0; for(int j=0;;j++){ b[j]=((j==N-1?S:q[j].front())+a[j]+a[j+1])%mod; if(j==N-1) break; ll t=q[j].front(),tmp=s[j];q[j].pop(); q[j].push(S); (s[j]+=S-t+mod)%=mod; (S+=tmp)%=mod; } for(int j=0;j<N;j++){ (s[j]+=b[j]-a[j]+mod)%=mod; a[j]=b[j]; } } for(int i=0;i<N;i++) (res+=s[i])%=mod; cout<<res<<endl; }