After I read the solution to the problem, I found that my solution was simply unsightly.

Solved 4 out of 7, and my solution to C was hacked, because of my incorrect order when i meet in the middle.

I wasted about 20 mins on problem A due to the incomprehensible description, at last i just find a harder solution and passed the pretests.

Neither have i read the questions calmly nor assigned time, that's why i got an unacceptable rank.

1073A - Diverse Substring

1073A - Diverse Substring

Notice that the string of two distinct letter is already diverse. That implies that the answer is "NO" if and only if all the letters in the string are the same. Otherwise you can check all pairs of adjacent letters in \(O(n)\)

Overall complexity: \(O(n)\)

n = int(input())
s = input()
for i in range(n - 1):
if (s[i] != s[i + 1]):
print("YES")
print(s[i], s[i + 1], sep="")
exit(0)
print("NO")

1073B - Vasya and Books

1073B - Vasya and Books

Let's maintain the pointer \(pos\) to the topmost non-deleted book and whether each book whether is removed from the stack or not. Initially, all books are in a stack, and \(pos\) is 0 (if we store the array 0-indexed). We will process the array \(B\) in the order \(b_1,b_2, \cdots, b_n\). If the current book \(b_i\) is removed from the stack, then the answer for it is zero. Otherwise, we will increment the pointer \(pos\) until the equality \(a_{pos} = b_i\) is satisfied, while marking all the intermediate books in the array \(u\). After that, the answer for the book

\(b_i\) will be the number of marked books in the \(u\) array (including itself).

Since the pointer \(pos\) shifts \(n\) times at total, we get a solution with an \(O(n)\) complexity.

#include <bits/stdc++.h>

using namespace std;

const int N = int(2e5) + 9;

int n, a[N], b[N];
bool u[N]; int main() {
scanf("%d", &n);
for(int i = 0; i < n; ++i) {
scanf("%d", a + i);
}
for(int i = 0; i < n; ++i){
scanf("%d", b + i);
} int pos = 0;
for(int i = 0; i < n; ++i){
int x = b[i];
if(u[x]){
printf("0 ");
continue;
} int cnt = 0;
while(true){
++cnt;
u[a[pos]] = true;
if(a[pos] == x) break;
++pos;
} ++pos;
printf("%d ", cnt);
} puts("");
return 0;
}

1073C - Vasya and Robot

1073C - Vasya and Robot

Denote \(d = |x| + |y|\). If \(d>n\), then the answer is -1, since the robot will not have the time to reach \((x, y)\) cell in \(n\) steps. Also, if \(d\) and \(n\) have different parity, then the answer is also -1, as in one move the robot changes the parity of the sum of its coordinates.

In all other cases, the answer exists. Let's use binary search to solve this problem. Consider all segments of length \(len\). For a fixed length of the segment \(len\), let's iterate over the position of the beginning of the segment \(l\). At the same time, we will maintain the cell that the robot will stop at if it execute all commands, except commands with indices \(l,l+1 \cdots,l+len−1\). We denote this position as \((x_0,y_0)\). We also calculate the distances from the cell \((x_0,y_0)\) to the cell \((x,y)\) — the value \(d_0=|x−x_0|+|y−y_0|\). If there is at least one position of the beginning of the segment for which \(d_0 \le len\) then we can change the segment of length \(len\) so that the robot comes to the \((x,y)\) cell, otherwise it can't.

const int maxn = 2e5 + 100;
int n, nx, ny, ans;
char str[maxn];
int lef[maxn], rgt[maxn], up[maxn], down[maxn]; int main() {
while (~scanf("%d %s %d %d", &n, str + 1, &nx, &ny)) {
seta(up, 0), seta(down, 0), seta(rgt, 0), seta(lef, 0);
if (abs(nx) + abs(ny) > n || ((abs(nx) + abs(ny)) & 1) != (n & 1)) return printf("-1\n"), 0;
for (int i = 1; i <= n; ++ i) {
if (str[i] == 'R') rgt[i] ++;
if (str[i] == 'U') up[i] ++;
if (str[i] == 'D') down[i] ++;
if (str[i] == 'L') lef[i] ++;
}
for (int i = 1; i <= n; ++ i) {
up[i] += up[i - 1];
rgt[i] += rgt[i - 1];
down[i] += down[i - 1];
lef[i] += lef[i - 1];
}
ans = 0x7fffffff;
if (nx < 0) {
for (int i = 1; i <= n; ++ i)
swap(lef[i], rgt[i]);
nx = -nx;
}
if (ny < 0) {
for (int i = 1; i <= n; ++ i) {
swap(up[i], down[i]);
}
ny = -ny;
}
if (rgt[n] - lef[n] == nx && up[n] - down[n] == ny)
return printf("0\n"), 0;
if (nx >= 0 && ny >= 0) {
for (int i = 1; i <= n; ++ i) {
int x1 = rgt[i - 1] - lef[i - 1];
int y1 = up[i - 1] - down[i - 1];
int l = i, r = n + 1;
while (l < r) {
int mid = (l + r) >> 1;
int x2 = rgt[n] - rgt[mid] - (lef[n] - lef[mid]);
int y2 = up[n] - up[mid] - (down[n] - down[mid]);
if ((mid - i + 1) >= (abs(nx - (x1 + x2)) + abs(ny - (y1 + y2)))) ans = min(ans, (r = mid) - i + 1); else l = mid + 1;
}
}
}
cout << ans << endl;
}
}

Educational Codeforces Round 53 Editorial的更多相关文章

  1. Educational Codeforces Round 53 E. Segment Sum(数位DP)

    Educational Codeforces Round 53 E. Segment Sum 题意: 问[L,R]区间内有多少个数满足:其由不超过k种数字构成. 思路: 数位DP裸题,也比较好想.由于 ...

  2. Educational Codeforces Round 53 (Rated for Div. 2) (前五题题解)

    这场比赛没有打,后来补了一下,第五题数位dp好不容易才搞出来(我太菜啊). 比赛传送门:http://codeforces.com/contest/1073 A. Diverse Substring ...

  3. Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum (数位dp求和)

    题目链接:https://codeforces.com/contest/1073/problem/E 题目大意:给定一个区间[l,r],需要求出区间[l,r]内符合数位上的不同数字个数不超过k个的数的 ...

  4. Educational Codeforces Round 53 (Rated for Div. 2)

    http://codeforces.com/contest/1073 A. Diverse Substring #include <bits/stdc++.h> using namespa ...

  5. [codeforces][Educational Codeforces Round 53 (Rated for Div. 2)D. Berland Fair]

    http://codeforces.com/problemset/problem/1073/D 题目大意:有n个物品(n<2e5)围成一个圈,你有t(t<1e18)元,每次经过物品i,如果 ...

  6. Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum

    https://codeforces.com/contest/1073/problem/E 题意 求出l到r之间的符合要求的数之和,结果取模998244353 要求:组成数的数位所用的数字种类不超过k ...

  7. Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 【二分 + 尺取】

    任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second mem ...

  8. Educational Codeforces Round 68 Editorial

    题目链接:http://codeforces.com/contest/1194                                            A.Remove a Progre ...

  9. Educational Codeforces Round 53 (Rated for Div. 2)G. Yet Another LCP Problem

    题意:给串s,每次询问k个数a,l个数b,问a和b作为后缀的lcp的综合 题解:和bzoj3879类似,反向sam日神仙...lcp就是fail树上的lca.把点抠出来建虚树,然后在上面dp即可.(感 ...

随机推荐

  1. 十天精通CSS3(7)

    :enabled选择器 在Web的表单中,有些表单元素有可用(“:enabled”)和不可用(“:disabled”)状态,比如输入框,密码框,复选框等.在默认情况之下,这些表单元素都处在可用状态.那 ...

  2. [lr] 直方图

    直方图基础知识 • 直方图的特征和作用 ▪ 直方图的x轴从左到右代表亮度逐渐增加,即从最暗到最亮:y轴代表某个亮度值下颜色像素的多少(密度). ▪ 直方图由红绿蓝三种颜色组成,分别表示红绿蓝通道:其中 ...

  3. 软件包管理:rpm命令管理-包命名与依赖性

    rpm包的管理主要有两种方法:一种是rpm命令管理另一种是yum在线管理 注意软件包没有扩展名,写上只是为了好看,便于识别而已. 注意区别包名,包全名.之所以要区分,就是因为有些命令十分挑剔,需要跟正 ...

  4. 原生 ajax

    1.创建XMLHttpRequest对象 var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Ope ...

  5. javascript技巧及常用事件方法集合(全)

    事件源对象 event.srcElement.tagName event.srcElement.type 捕获释放 event.srcElement.setCapture();  event.srcE ...

  6. linux常用命令:vmstat 命令

    vmstat 是Virtual Meomory Statistics(虚拟内存统计)的缩写,可对操作系统的虚拟内存.进程.CPU活动进行监控.他是对系统的整体 情况进行统计,不足之处是无法对某个进程进 ...

  7. python excel操作单元格复制和读取的两种方法

    操作单元格 新建一个sheet, 单元格赋值(两种方法) 单元格A1赋值为’xiaxiaoxu’ 单元格A2赋值为‘xufengchai’ 打印A1和A2单元格的值(两种方法) #coding=utf ...

  8. JSP禁用缓存常用方法

    内容主要转自:http://www.cnblogs.com/linjiqin/archive/2011/07/20/2111627.html jsp页面禁止缓存设置 1.客户端缓存要在<head ...

  9. Linux基础命令---sudo

    sudo sudo允许用户以超级用户或安全策略指定的另一个用户的身份执行命令.Sudo支持安全策略插件和输入/输出日志的插件.第三方可以开发和分发自己的策略和I/O日志插件,以便与sudo前端无缝地工 ...

  10. 09: TemplateView , ListView ,DetailView三种常用类视图用法

    1.1 视图混合介绍 1.Mixin和View的职能区分 1. Mixin提供数据,View提供模板和渲染,所以一般get_context_data在Mixin中,get(),post(),head( ...