이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll md = 1000000007;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m; cin >> n >> m;
vector<vector<int>> gr(n), lr(n);
vector<vector<int>> grr(n), lrr(n);
for(int i = 0; i < m; i++){
int a, b; cin >> a >> b; a--, b--;
if(a < b) lr[a+1].pb(i), lrr[b].pb(i);
else gr[b+1].pb(i), grr[a].pb(i);
}
vector<vector<ll>> dp(n, vector<ll>(26, 0));
dp[n-1] = vector<ll>(26, 1);
for(int I = n-2; I >= 0; I--) for(int J = 0; J < 26; J++){
set<int> s1, s2;
for(int i = I+1; i < n; i++){
if(i != 0){
for(int x: grr[i-1]) s1.erase(x);
for(int x: lrr[i-1]) s2.erase(x);
}
for(int x: gr[i]) s1.insert(x);
for(int x: lr[i]) s2.insert(x);
if(s1.empty() && s2.empty()){
for(int j = 0; j < 26; j++) dp[I][J]+=dp[i][j], dp[I][J]%=md;
break;
}
if(!s1.empty() && !s2.empty()){
if(i == n-1) dp[I][J]++, dp[I][J]%=md;
continue;
}
if(!s1.empty()) for(int j = J+1; j < 26; j++) dp[I][J]+=dp[i][j], dp[I][J]%=md;
else for(int j = 0; j < J; j++) dp[I][J]+=dp[i][j], dp[I][J]%=md;
if(i == n-1) dp[I][J]++, dp[I][J]%=md;
}
}
ll ans = 0;
for(ll x: dp[0]) ans+=x, ans%=md;
cout << ans << "\n";
}
# | 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... |