이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
llo n,k;
llo mod=1e9+7;
llo it[200001];
llo dp[2001][2001];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>k;
for(llo i=0;i<n;i++){
cin>>it[i];
}
dp[0][n-1]=1;
for(llo i=n-2;i>=0;i--){
for(llo j=0;j+i<n;j++){
dp[j][j+i]=0;
llo x=0;
if(j>0){
x=max(x,it[j-1]);
}
if(j+i+1<n){
x=max(x,it[j+i+1]);
}
if(j>0){
if(it[j-1]==x){
dp[j][j+i]+=dp[j-1][j+i];
}
}
if(j+i+1<n){
if(it[j+i+1]==x){
dp[j][j+i]+=dp[j][j+i+1];
}
}
dp[j][j+i]%=mod;
}
}
vector<llo> ss;
for(llo i=0;i<k;i++){
llo aa;
cin>>aa;
ss.pb(aa-1);
}
for(auto j:ss){
cout<<dp[j][j]<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |