이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 3e5 + 5;
const int mod = 1e9 + 7, oo = 1e18 + 7;
int n, q, a[N];
vector<iii> ques;
int dp[N][26];
int pref[N][26], suff[N][26];
int ck(int i, int j){// ck = 0 -> < , ck = 1 -> >; j < i
bool ck0 = 1, ck1 = 1;
for(auto it : ques){
if(it.fi.fi > j && it.fi.fi <= i && it.fi.se >= i){
ck0 &= (it.se == 0);
ck1 &= (it.se == 1);
}
}
if(!ck0 && !ck1) return -1;
else if(!ck1) return 0;
else if(!ck0) return 1;
else return 2;
}
void add(int &a, int b){
a = (a + b) % mod;
}
void process(){
cin >> n >> q;
for(int i = 1; i <= q; i++){
int x, y;
cin >> x >> y;
if(x == y) continue;
if(x < y) ques.pb({{x + 1, y}, 0});
else ques.pb({{y + 1, x}, 1});
}
for(int i = 0; i < 26; i++) dp[1][i] = 1;
for(int i = 1; i <= n; i++){
for(int j = 1; j < i; j++){
int temp = ck(i, j);
//cout << i << " " << j << " " << temp << "\n";
if(temp == 0 || temp == 2){
for(int k = 0; k < 26; k++){
for(int h = 0; h < k; h++){
add(dp[i][k], dp[j][h]);
}
}
}
if(temp == 1 || temp == 2){
for(int k = 0; k < 26; k++){
for(int h = k + 1; h < 26; h++){
add(dp[i][k], dp[j][h]);
}
}
}
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
for(int j = 0; j < 26; j++){
add(ans, dp[i][j]);
}
}
cout << ans << "\n";
}
signed main(){
ios_base::sync_with_stdio(0);
//freopen("KEK.inp", "r", stdin);
//freopen("KEK.out", "w", stdout);
cin.tie(0);
process();
}
# | 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... |