This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int nx=2e3+5, kx=26, mod=1e9+7;
int n, m, a, b, dp[nx][kx], res, cu[nx], cd[nx];
vector<int> up[nx], dn[nx];
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
for (int i=1; i<=m; i++)
{
cin>>a>>b;
if (a<b) dn[a+1].push_back(b);
else up[b+1].push_back(a);
}
for (int i=n; i>=1; i--)
{
for (int c=0; c<26; c++)
{
dp[i][c]=1;
for (int j=i+1; j<=n; j++)
{
if (!cu[j])
{
for (int d=0; d<c; d++)
{
dp[i][c]=(dp[i][c]+dp[j][d])%mod;
}
}
if (!cd[j])
{
for (int d=c+1; d<26; d++)
{
dp[i][c]=(dp[i][c]+dp[j][d])%mod;
}
}
}
//cout<<"debug "<<i<<' '<<c<<' '<<dp[i][c]<<'\n';
}
for (auto x:up[i]) for (int j=i; j<=x; j++) cu[j]=1;
for (auto x:dn[i]) for (int j=i; j<=x; j++) cd[j]=1;
}
for (int c=0; c<26; c++) res=(res+dp[1][c])%mod;
cout<<res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |