Submission #556939

#TimeUsernameProblemLanguageResultExecution timeMemory
556939DanShadersMisspelling (JOI22_misspelling)C++17
8 / 100
4091 ms131912 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

namespace x = __gnu_pbds;
template <typename T>
using ordered_set = x::tree<T, x::null_type, less<T>, x::rb_tree_tag, x::tree_order_statistics_node_update>;

template <typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;

#define all(x) begin(x), end(x)
#define sz(x) ((int) (x).size())
#define x first
#define y second
using ll = long long;
using ld = long double;

#define int ll

const int N = 5e5 + 10, C = 26, MOD = 1e9 + 7;

ll dp[N][C];

signed main() {
	cin.tie(0)->sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	vector<tuple<int, int, bool>> a(m);
	for (int i = 0; i < m; ++i) {	
		int u, v;
		cin >> u >> v;
		--u, --v;
		a.push_back({min(u, v), max(u, v), u > v});
	}
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < C; ++j) {
			dp[i][j] = 1;
		}
	}
	for (int i = n - 1; i > 0; --i) {
		for (int c0 = 0; c0 < C; ++c0) {
			for (int c1 = 0; c1 < C; ++c1) {
				if (c0 == c1) {
					continue;
				}
				for (int j = i - 1; j >= 0; --j) {
					bool flag[2]{};
					for (auto [l, r, f] : a) {
						if (r >= i && l < i && l >= j) {
							flag[f] = 1;
						}
					}
					if (c1 < c0 && !flag[1]) {
						(dp[j][c1] += dp[i][c0]) %= MOD;
					}
					if (c1 > c0 && !flag[0]) {
						(dp[j][c1] += dp[i][c0]) %= MOD;
					}
				}
			}
		}
	}
	cout << accumulate(dp[0], dp[1], 0ll) % MOD;
}
#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...