제출 #764985

#제출 시각아이디문제언어결과실행 시간메모리
764985ymmMisspelling (JOI22_misspelling)C++17
28 / 100
4086 ms4528 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];
ll ps[N][alpha+1];
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;
	Loop (x,0,alpha)
		ps[n][x+1] = 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) {
					ans += ps[j][alpha];
					goto end;
				} else if (j > b) {
					ans += ps[j][alpha];
					ans -= ps[j][x+1];
				} else if (j > a) {
					ans += ps[j][x];
				}
				a = max(a, mxa[j]);
				b = max(b, mxb[j]);
				ans %= mod;
			}
		end:
			ans %= mod;
			dp[i][x] = ans;
		}
		Loop (x,0,alpha)
			ps[i][x+1] = ps[i][x] + dp[i][x];
	}
	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...