Submission #764983

#TimeUsernameProblemLanguageResultExecution timeMemory
764983ymmMisspelling (JOI22_misspelling)C++17
28 / 100
4072 ms11096 KiB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 20'010;
const int alpha = 26;
const int mod = 1e9+7;

ll dp[N][alpha];
int mxa[N], mxb[N];
int n, m;

int main()
{
	cin.tie(0) -> sync_with_stdio(false);
	cin >> n >> m;
	Loop (_,0,m) {
		int i, j;
		cin >> i >> j;
		--i; --j;
		if (i < j)
			mxa[i] = max(mxa[i], j);
		else
			mxb[j] = max(mxb[j], i);
	}
	dp[n][0] = 1;
	LoopR (i,0,n) Loop (x,0,alpha) {
		ll ans = 0;
		int a = mxa[i], b = mxb[i];
		Loop (j,i+1,n+1) {
			if (j > a && j > b) {
				Loop (y,0,alpha)
					ans += dp[j][y];
				goto end;
			} else if (j > b) {
				Loop (y,x+1,alpha)
					ans += dp[j][y];
			} else if (j > a) {
				Loop (y,0,x)
					ans += dp[j][y];
			}
			a = max(a, mxa[j]);
			b = max(b, mxb[j]);
			ans %= mod;
		}
	end:
		ans %= mod;
		dp[i][x] = ans;
	}
	ll ans = 0;
	Loop (x,0,alpha)
		ans += dp[0][x];
	ans %= mod;
	cout << ans << '\n';
}
#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...