A. Remainder

output

standard output

You are given a huge decimal number consisting of nn digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1.

You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0 to 1 or 1 to 0. It is possible that after some operation you can obtain a number with leading zeroes, but it does not matter for this problem.

You are also given two integers 0≤y<x<n0≤y<x<n. Your task is to calculate the minimum number of operations you should perform to obtain the number that has remainder 10y10y modulo 10x10x. In other words, the obtained number should have remainder 10y10y when divided by 10x10x.

Input

The first line of the input contains three integers n,x,yn,x,y (0≤y<x<n≤2⋅1050≤y<x<n≤2⋅105) — the length of the number and the integers xxand yy, respectively.

The second line of the input contains one decimal number consisting of nn digits, each digit of this number is either 0 or 1. It is guaranteed that the first digit of the number is 1.

Output

Print one integer — the minimum number of operations you should perform to obtain the number having remainder 10y10y modulo 10x10x. In other words, the obtained number should have remainder 10y10y when divided by 10x10x.

Examples
input

Copy
  1. 11 5 2
  2. 11010100101
output

Copy
  1. 1
input

Copy
  1. 11 5 1
  2. 11010100101
output

Copy
  1. 3
Note

In the first example the number will be 1101010010011010100100 after performing one operation. It has remainder 100100 modulo 100000100000.

In the second example the number will be 1101010001011010100010 after performing three operations. It has remainder 1010 modulo 100000100000.

思路:只需要看需要的位数

代码:

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<queue>
  6. #include<stack>
  7. #include<set>
  8. #include<vector>
  9. #include<map>
  10. #include<cmath>
  11. const int maxn=1e5+;
  12. typedef long long ll;
  13. using namespace std;
  14.  
  15. char a[*maxn];
  16. int main()
  17. {
  18. int n,x,y;
  19. cin>>n>>x>>y;
  20. scanf("%s",a);
  21. int sum=;
  22.  
  23. for(int t=n-;t>=n-x;t--)
  24. {
  25. if(a[t]==''&&t!=n-y-)
  26. {
  27. continue;
  28. }
  29. else if(a[t]==''&&t!=n-y-)
  30. {
  31. sum++;
  32. }
  33. else if(a[t]==''&&t==n-y-)
  34. {
  35. continue;
  36. }
  37. else if(a[t]==''&&t==n-y-)
  38. {
  39. sum++;
  40. }
  41. }
  42. printf("%d",sum);
  43. return ;
  44. }

B. Polycarp Training

Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly 11 problem, during the second day — exactly 22 problems, during the third day — exactly 33 problems, and so on. During the kk-th day he should solve kk problems.

Polycarp has a list of nn contests, the ii-th contest consists of aiai problems. During each day Polycarp has to choose exactly one of the contests he didn't solve yet and solve it. He solves exactly kk problems from this contest. Other problems are discarded from it. If there are no contests consisting of at least kk problems that Polycarp didn't solve yet during the kk-th day, then Polycarp stops his training.

How many days Polycarp can train if he chooses the contests optimally?

Input

The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of contests.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤2⋅1051≤ai≤2⋅105) — the number of problems in the ii-th contest.

Output

Print one integer — the maximum number of days Polycarp can train if he chooses the contests optimally.

Examples
input

Copy
  1. 4
  2. 3 1 4 1
output

Copy
  1. 3
input

Copy
  1. 3
  2. 1 1 1
output

Copy
  1. 1
input

Copy
  1. 5
  2. 1 1 1 2 2
output

Copy
  1. 2

思路:优先队列

代码:

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<algorithm>
  5. #include<queue>
  6. #include<stack>
  7. #include<set>
  8. #include<map>
  9. #include<algorithm>
  10. #include<vector>
  11.  
  12. const int maxn=2e5+;
  13. typedef long long ll;
  14. using namespace std;
  15. priority_queue<int,vector<int>,greater<int> >q;
  16. int main()
  17. {
  18. int n,x;
  19. cin>>n;
  20. for(int i=;i<=n;i++)
  21. {
  22. cin>>x;
  23. q.push(x);
  24. }
  25. int ans=;
  26. for(int i=;;i++)
  27. {
  28. while(!q.empty())
  29. {
  30. x=q.top();q.pop();
  31. if(x>=i)
  32. {
  33. x-=i;
  34. ans=i;
  35. break;
  36. }
  37. }
  38. if(q.empty())
  39. break;
  40. }
  41. cout<<ans;
  42. }

C. Good String

Let's call (yet again) a string good if its length is even, and every character in odd position of this string is different from the next character (the first character is different from the second, the third is different from the fourth, and so on). For example, the strings good, string and xyyx are good strings, and the strings bad, aa and aabc are not good. Note that the empty string is considered good.

You are given a string ss, you have to delete minimum number of characters from this string so that it becomes good.

Input

The first line contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of characters in ss.

The second line contains the string ss, consisting of exactly nn lowercase Latin letters.

Output

In the first line, print one integer kk (0≤k≤n0≤k≤n) — the minimum number of characters you have to delete from ss to make it good.

In the second line, print the resulting string ss. If it is empty, you may leave the second line blank, or not print it at all.

Examples
input

Copy
  1. 4
  2. good
output

Copy
  1. 0
  2. good
input

Copy
  1. 4
  2. aabc
output

Copy
  1. 2
  2. ab
input

Copy
  1. 3
  2. aaa
output

Copy
  1. 3

用队列模拟一下取不取的过程

代码:

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<queue>
  6. #include<stack>
  7. #include<set>
  8. #include<vector>
  9. #include<map>
  10. #include<cmath>
  11. const int maxn=1e5+;
  12. typedef long long ll;
  13. using namespace std;
  14. char str[*maxn];
  15. int main()
  16. {
  17. int n;
  18. cin>>n;
  19. scanf("%s",str+);
  20. int sum=;
  21. char ss=str[];
  22. queue<char>q;
  23. q.push(ss);
  24. for(int t=;t<=n;t++)
  25. {
  26. if(sum%==&&str[t]==ss)
  27. {
  28. continue;
  29. }
  30. sum++;
  31. ss=str[t];
  32. q.push(str[t]);
  33. }
  34. if(sum%==)
  35. {
  36. sum--;
  37. }
  38. printf("%d\n",n-sum);
  39. int cnt=;
  40. while(!q.empty())
  41. {
  42. if(cnt==sum)
  43. {
  44. break;
  45. }
  46. cnt++;
  47. printf("%c",q.front());
  48. q.pop();
  49. }
  50. printf("\n");
  51.  
  52. return ;
  53. }

D. Almost All Divisors

We guessed some integer number xx. You are given a list of almost all its divisors. Almost all means that there are all divisors except 11 and xx in the list.

Your task is to find the minimum possible integer xx that can be the guessed number, or say that the input data is contradictory and it is impossible to find such number.

You have to answer tt independent queries.

Input

The first line of the input contains one integer tt (1≤t≤251≤t≤25) — the number of queries. Then tt queries follow.

The first line of the query contains one integer nn (1≤n≤3001≤n≤300) — the number of divisors in the list.

The second line of the query contains nn integers d1,d2,…,dnd1,d2,…,dn (2≤di≤1062≤di≤106), where didi is the ii-th divisor of the guessed number. It is guaranteed that all values didi are distinct.

Output

For each query print the answer to it.

If the input data in the query is contradictory and it is impossible to find such number xx that the given list of divisors is the list of almost all its divisors, print -1. Otherwise print the minimum possible xx.

Example
input

Copy
  1. 2
  2. 8
  3. 8 2 12 6 4 24 16 3
  4. 1
  5. 2
output

Copy
  1. 48
  2. 4

前面有此题的思路和代码

E. Two Arrays and Sum of Functions

You are given two arrays aa and bb, both of length nn.

Let's define a function f(l,r)=∑l≤i≤rai⋅bif(l,r)=∑l≤i≤rai⋅bi.

Your task is to reorder the elements (choose an arbitrary order of elements) of the array bb to minimize the value of ∑1≤l≤r≤nf(l,r)∑1≤l≤r≤nf(l,r). Since the answer can be very large, you have to print it modulo 998244353998244353. Note that you should minimize the answer but not its remainder.

Input

The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of elements in aa and bb.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1061≤ai≤106), where aiai is the ii-th element of aa.

The third line of the input contains nn integers b1,b2,…,bnb1,b2,…,bn (1≤bj≤1061≤bj≤106), where bjbj is the jj-th element of bb.

Output

Print one integer — the minimum possible value of ∑1≤l≤r≤nf(l,r)∑1≤l≤r≤nf(l,r) after rearranging elements of bb, taken modulo 998244353998244353. Note that you should minimize the answer but not its remainder.

Examples
input

Copy
  1. 5
  2. 1 8 7 2 4
  3. 9 7 2 9 3
output

Copy
  1. 646
input

Copy
  1. 1
  2. 1000000
  3. 1000000
output

Copy
  1. 757402647
input

Copy
  1. 2
  2. 1 3
  3. 4 2
output

Copy
  1. 20

思考贡献次数和排序

注意取模

代码:

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<iostream>
  4. #include<algorithm>
  5. #include<queue>
  6. #include<stack>
  7. #include<set>
  8. #include<map>
  9. #include<algorithm>
  10. #include<vector>
  11.  
  12. const int maxn=1e5+;
  13. typedef long long ll;
  14. using namespace std;
  15. ll a[*maxn],b[maxn*];
  16. bool cmp(int x,int y)
  17. {
  18. return x>y;
  19. }
  20. int main()
  21. {
  22. int n;
  23. cin>>n;
  24. for(int t=;t<n;t++)
  25. {
  26. scanf("%lld",&a[t]);
  27. a[t]=(a[t]*(n-t)*(t+));
  28. }
  29. for(int t=;t<n;t++)
  30. {
  31. scanf("%lld",&b[t]);
  32. }
  33. sort(a,a+n);
  34. sort(b,b+n,cmp);
  35. ll ans=;
  36. for(int t=;t<n;t++)
  37. {
  38.  
  39. ans=(ans%+((a[t]%)*(b[t]%))%)%;
  40. }
  41. printf("%lld",ans);
  42.  
  43. return ;
  44. }

Codeforces Round #560 (Div. 3)A-E的更多相关文章

  1. Codeforces Round #560 (Div. 3) Microtransactions

    Codeforces Round #560 (Div. 3) F2. Microtransactions (hard version) 题意: 现在有一个人他每天早上获得1块钱,现在有\(n\)种商品 ...

  2. A. Remainder Codeforces Round #560 (Div. 3)

    A. Remainder Codeforces Round #560 (Div. 3) You are given a huge decimal number consisting of nn dig ...

  3. Codeforces Round #560 Div. 3

    题目链接:戳我 于是...风浔凌弱菜又去写了一场div.3 总的来说,真的是比较简单.......就是.......不开long long见祖宗 贴上题解-- A 给定一个数,为01串,每次可以翻转一 ...

  4. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  5. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  6. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  7. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  8. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  9. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

随机推荐

  1. tensorboard报错:AttributeError: ‘Value’ object has no attribute ‘metadata’

    tensorboard的网页可以访问,但是只能观察到graph数据,但是观察不到scalars数据. 原因:tensorflow版本需>=1.3.0 解决方法:升级tensorflow

  2. IdentityServer4 (1) 客户端授权模式(Client Credentials)

    写在前面 1.源码(.Net Core 2.2) git地址:https://github.com/yizhaoxian/CoreIdentityServer4Demo.git 2.相关章节 2.1. ...

  3. 极简 Node.js 入门 - 1.2 模块系统

    极简 Node.js 入门系列教程:https://www.yuque.com/sunluyong/node 本文更佳阅读体验:https://www.yuque.com/sunluyong/node ...

  4. LDAP 使用记录

    LDAP 命令记录 工作中用到了 LDAP,做一个简单记录. 概念性的东西不做阐述,只是记录常用命令,以便将来回顾. 想多做了解可以参考这个系列文章: https://blog.csdn.net/li ...

  5. Dubbo系列之 (一)SPI扩展

    一.基础铺垫 1.@SPI .@Activate. @Adaptive a.对于 @SPI,Dubbo默认的特性扩展接口,都必须打上这个@SPI,标识这是个Dubbo扩展点.如果自己需要新增dubbo ...

  6. idea只导入部分依赖

    首先为啥会导入部分依赖的呢? 可能是网络问题下载不下来,可以排除这一个,因为刚换的merrio阿里的源,而且之前都能下载 也可能是maven的设置问题,上网上搜了一些设置之后,还是不管用 然后怀疑是不 ...

  7. 编程与算法(一)、C语言实现二分法(方程近似解)

    一.二分法 假设有这样一个函数f(x) 函数与x轴有一个交点(也就是f(a)*f(b)<0,a<b),现在我们要求这个点的x值,也就是方程f(x)=0的一个实根 直接解显然不合适,那么接下 ...

  8. 【模式识别与机器学习】——logistic regression

    虽然叫做“回归”,但是这个算法是用来解决分类问题的.回归与分类的区别在于:回归所预测的目标量的取值是连续的(例如房屋的价格):而分类所预测的目标变量的取值是离散的(例如判断邮件是否为垃圾邮件).当然, ...

  9. Django中的ORM如何通过数据库中的表格信息自动化生成Model 模型类?

    Inspectdb Django项目通过绑定的数据库中的相应表格直接自动化生成Model 模型类 python manage.py inspectdb Django 中的 ORM 可以实现对象关系映射 ...

  10. golang 复数

    目录 1.声明/赋值/初始化 2.类型 3.取虚实部数值 4.运算 5.注意 跳转 1.声明/赋值/初始化 var name complex128 =complex(x,v) name := comp ...