记录编号 446849 评测结果 AAAAAAAAAA
题目名称 [Codeforces 819A] B先生和无聊的游戏 最终得分 100
用户昵称 GravatarAAAAAAAAAA 是否通过 通过
代码语言 C++ 运行时间 0.003 s
提交时间 2017-09-08 22:28:16 内存使用 0.31 MiB
显示代码纯文本
//周期为2*(a+b) 若a>b+1一个周期包含2a-b个元素否则包含a+1个  
#define _CRT_SECURE_NO_WARNINGS
#include<string>
#include<cstdio>
#include<iostream>
using namespace std;
int a, b, l, r, T, sum, num[30],ans;
bool vis[27];
string s;
int main() {
	freopen("MrBA1.in", "r", stdin);
	freopen("MrBA1.out", "w", stdout);
	scanf("%d%d%d%d", &a, &b, &l, &r);
	T = (a + b) << 1;
	if (a>b + 1)sum = (a << 1) - b;
	else sum = a + 1;
	if (r - l >= T) { printf("%d", sum); return 0; }
	l %= T; r %= T;
	l++, r++;
	for (int i = 0; i < a; i++)s += char('a' + i);
	for (int i = 0; i < b; i++)s += char('a' + a - 1);
	if (a > b + 1) {
		for (int i = 0; i < b; i++)s += char('a'  + i);
		for (int i = 0; i < a-b; i++)s += char('a' + a+i);
		for (int i = 0; i < b; i++)s += char('a' + a + a-b-1);
		for (int i = l - 1; i < r; i++)if (!vis[s[i] - 'a'])vis[s[i] - 'a']++, ans++;
		//cout << s<<endl;
		printf("%d", ans);
	}
	else {
		for (int i = 0; i < a; i++)s += char('a' + i);
		for (int i = 0; i < b; i++)s += char('a' + a + a - 1);
		for (int i = l - 1; i < r; i++)if (!vis[s[i] - 'a'])vis[s[i] - 'a']++, ans++;
		//cout << s<<endl;
		printf("%d", ans);
	}
	return 0;
}