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;
#define int long long
const int MOD = 1e9+7;
int n,m;
int dp[500005][30];
vector<pair<int,int>> qrysle[500005];
vector<pair<int,int>> secv[2];
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n>>m;
int a,b;
for(int i=1;i<=m;i++)
{
cin>>a>>b;
if(a==b)
continue;
if(a<b)
{
qrysle[a+1].push_back({b,0});
secv[0].push_back({a+1,b});
}
else
{
swap(a,b);
qrysle[a+1].push_back({b,1});
secv[1].push_back({a+1,b});
}
}
for(int c=0;c<26;c++)
dp[1][c]=1;
int rez=26;
for(int i=2;i<=n;i++)
{
for(int c=0;c<26;c++)
{
int p0=1,p1=1;
for(auto x:secv[0])
if(x.first<=i && x.second>=i)
p0 = max(p0, x.first);
for(auto x:secv[1])
if(x.first<=i && x.second>=i)
p1 = max(p1, x.first);
for(int x=p1;x<i;x++)
for(int u=c+1;u<26;u++)
dp[i][c] += dp[x][u];
for(int x=p0;x<i;x++)
for(int u=0;u<c;u++)
dp[i][c] += dp[x][u];
dp[i][c]%=MOD;
rez = (rez + dp[i][c])%MOD;
}
}
cout<<rez;
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |