提交记录 9969


用户 题目 状态 得分 用时 内存 语言 代码长度
cold_chair noi19b. 【NOI2019】机器人 Accepted 100 2.371 s 82196 KB C++ 2.32 KB
提交时间 评测时间
2019-07-31 22:40:18 2020-08-01 02:00:00
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

const int N = 605;

int n, a[N], b[N], c[N], c0;
int bz[N][N], bz0;
int cnt;

const int mo = 1e9 + 7;

ll ksm(ll x, ll y) {
	ll s = 1;
	for(; y; y /= 2, x = x * x % mo)
		if(y & 1) s = s * x % mo;
	return s;
}

ll fac[N], nf[N], nf2[N];

void build(int n) {
	fac[0] = nf[0] = nf2[0] = 1;
	fo(i, 1, n) fac[i] = fac[i - 1] * i % mo;
	fo(i, 1, n) {
		nf[i] = ksm(fac[i], mo - 2);
		nf2[i] = ksm(i & 1 ? mo - fac[i] : fac[i], mo - 2);
	}
}

vector<int> d[1900][610];

ll p[N], q[N], p1[N], q1[N];

ll cz(ll x, int n) {
	fo(i, 0, n) {
		p1[i] = (!i ? 1 : p1[i - 1]) * (x - p[i]) % mo;
	}
	fd(i, n, 0) {
		q1[i] = (i == n ? 1 : q1[i + 1]) * (x - p[i]) % mo;
	}
	ll ans = 0;
	fo(i, 0, n) if(q[i]) {
		ans = (ans + q[i] * (!i ? 1 : p1[i - 1]) % mo * (i == n ? 1 : q1[i + 1]) % mo * nf[i] % mo * nf2[n - i]) % mo;
	}
	return ans;
}

ll query(int l, int r, int x, int w) {
	if(l > r) return 1;
	if(l == r) return max(0, min(x, b[l]) - a[l] + 1);
	int num = bz[l][r];
	if(x - c[w] <= r - l + 1) return d[num][w][x - c[w]];
	fo(i, 0, r - l + 1)	p[i] = c[w] + i, q[i] = d[num][w][i];
	return cz(x, r - l + 1);
}

void dg(int x, int y) {
	if(x >= y) return;
	if(bz[x][y]) return;
	bz[x][y] = ++ bz0;
	int num = bz[x][y];
	fo(i, x, y)	if(abs(i - x - (y - i)) <= 2) {
		dg(x, i - 1); dg(i + 1, y);
	}
	fo(j, 1, c0 - 1) {
		int mx = min(y - x + 1, c[j + 1] - c[j] - 1);
		d[num][j].resize(mx + 1);
		ll sum = (j == 1 ? 0 : query(x, y, c[j] - 1, j - 1));
		fo(k, 0, mx) {
			int mi = x + y >> 1;
			fo(i, max(x, mi - 1), min(y, mi + 1)) if(abs(i - x - (y - i)) <= 2) {
				if(c[j] + k >= a[i] && c[j] + k <= b[i])
					sum = (sum + query(x, i - 1, c[j] + k, j) * query(i + 1, y, c[j] + k - 1, j + (!k ? -1 : 0))) % mo;
			}
			d[num][j][k] = sum;
		}
	}
}

int main() {
	freopen("robot.in", "r", stdin);
	freopen("robot.out", "w", stdout);
	build(301);
	scanf("%d", &n);
	c[++ c0] = 0; c[++ c0] = 1e9 + 1;
	fo(i, 1, n) scanf("%d %d", &a[i], &b[i]), c[++ c0] = a[i], c[++ c0] = b[i];
	sort(c + 1, c + c0 + 1);
	c0 = unique(c + 1, c + c0 + 1) - (c + 1);
	dg(1, n);
	pp("%lld\n", (query(1, n, 1e9, c0 - 1) + mo) % mo);
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #14.717 ms26 MB + 632 KBAcceptedScore: 5

Testcase #24.719 ms26 MB + 632 KBAcceptedScore: 5

Testcase #34.709 ms26 MB + 624 KBAcceptedScore: 5

Testcase #44.834 ms26 MB + 624 KBAcceptedScore: 5

Testcase #55.529 ms27 MB + 56 KBAcceptedScore: 5

Testcase #65.364 ms27 MB + 12 KBAcceptedScore: 5

Testcase #75.353 ms27 MB + 4 KBAcceptedScore: 5

Testcase #8338.889 ms61 MB + 224 KBAcceptedScore: 5

Testcase #9360.585 ms57 MB + 760 KBAcceptedScore: 5

Testcase #10336.013 ms60 MB + 556 KBAcceptedScore: 5

Testcase #114.961 ms26 MB + 704 KBAcceptedScore: 5

Testcase #124.981 ms26 MB + 720 KBAcceptedScore: 5

Testcase #1315.39 ms27 MB + 516 KBAcceptedScore: 5

Testcase #1411.674 ms27 MB + 408 KBAcceptedScore: 5

Testcase #1511.145 ms27 MB + 244 KBAcceptedScore: 5

Testcase #16230.004 ms36 MB + 512 KBAcceptedScore: 5

Testcase #17216.653 ms36 MB + 320 KBAcceptedScore: 5

Testcase #18691.571 ms48 MB + 200 KBAcceptedScore: 5

Testcase #19642.962 ms50 MB + 268 KBAcceptedScore: 5

Testcase #202.371 s80 MB + 276 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-04-25 14:34:33 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用