Submission #709195

#TimeUsernameProblemLanguageResultExecution timeMemory
709195minhcoolMisspelling (JOI22_misspelling)C++17
28 / 100
4030 ms18880 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...