Codeforces Round #560 (Div. 3)ABCDE

A. Remainder
You are given a huge decimal number consisting of n 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<n. Your task is to calculate the minimum number of operations you should perform to obtain the number that has remainder 10y modulo 10x. In other words, the obtained number should have remainder 10y when divided by 10x.

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

The second line of the input contains one decimal number consisting of n 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 10y modulo 10x. In other words, the obtained number should have remainder 10y when divided by 10x.

Examples
Input
11 5 2
11010100101
Output
1
Input
11 5 1
11010100101
Output
3
Note
In the first example the number will be 11010100100 after performing one operation. It has remainder 100 modulo 100000.

In the second example the number will be 11010100010 after performing three operations. It has remainder 10 modulo 100000.
题意不解释,沙雕题目。注意细节就好了

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<string>
using namespace std;

int n,x,y;
string s;

int main()
{
	while(scanf("%d%d%d",&n,&x,&y)!=EOF)
	{
		cin>>s;
		int sum=0;
		for(int i=n-1;i>=n-y;i--)
		{
			if(s[i]=='1') sum++;
		}
		if(s[n-y-1]=='0') sum++;
		for(int i=n-y-2;i>=n-x;i--)
		{
			if(s[i]=='1') sum++;
		}
		cout<<sum<<endl;
	}
}

B Polycarp Training
Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly 1 problem, during the second day — exactly 2 problems, during the third day — exactly 3 problems, and so on. During the k-th day he should solve k problems.

Polycarp has a list of n contests, the i-th contest consists of ai problems. During each day Polycarp has to choose exactly one of the contests he didn’t solve yet and solve it. He solves exactly k problems from this contest. Other problems are discarded from it. If there are no contests consisting of at least k problems that Polycarp didn’t solve yet during the k-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 n (1≤n≤2⋅105) — the number of contests.

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

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

Examples
Input
4
3 1 4 1
Output
3
Input
3
1 1 1
Output
1
Input
5
1 1 1 2 2
Output
2

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define ll long long
using namespace std;

const int maxx=2e5+100;
ll a[maxx];
int n;

int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=0;i<n;i++) scanf("%d",&a[i]);
		sort(a,a+n);
		int sum=0;
		int cnt=1;
		for(int i=0;i<n;i++)
		{
			if(a[i]>=cnt) sum++,cnt++;
		}
		cout<<sum<<endl;
	}
}

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 s, you have to delete minimum number of characters from this string so that it becomes good.

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

The second line contains the string s, consisting of exactly n lowercase Latin letters.

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

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

Examples
Input
4
good
Output
0
good
Input
4
aabc
Output
2
ab
Input
3
aaa
Output
3

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<string>
using namespace std;

string s;
int n;

int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		cin>>s;
		int sum=0;
		string ss;
		for(int i=1;i<n;)
		{
			if(s[i]!=s[i-1])
			{
				ss+=s[i-1];
				ss+=s[i];
				i+=2;
			}
			else
			{
				i++;
				sum++;
			}
		}
		if((n-sum)&1) sum++;
		cout<<sum<<endl<<ss<<endl;
	}
}

D Almost All Divisors
We guessed some integer number x. You are given a list of almost all its divisors. Almost all means that there are all divisors except 1 and x in the list.

Your task is to find the minimum possible integer x 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 t independent queries.

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

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

The second line of the query contains n integers d1,d2,…,dn (2≤di≤106), where di is the i-th divisor of the guessed number. It is guaranteed that all values di 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 x that the given list of divisors is the list of almost all its divisors, print -1. Otherwise print the minimum possible x.

Example
Input
2
8
8 2 12 6 4 24 16 3
1
2
Output
48
4
给你一个数的除了1和它本身外的所有因子,问能不能判断出来这个数,并且最小是多少。
思路:一个数的因子,最大的乘以最小的就是这个数本身,次大的乘以次小的也是这个数,以此类推。
排个序之后,从两边往中间找。看看最后因子的个数是不是n就好了
代码如下:

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
int main()
{
    int T;
    cin>>T;
    while(T--)
	{
        int n;
        cin>>n;
        vector<ll>v;
        for(int i=1;i<=n;i++)
		{
            int x;
            cin>>x;
            v.push_back(x);
        }
        sort(v.begin(),v.end());
        ll ans=v[0]*v[v.size()-1];
        int sum=0,flag=1;
        for(ll i=2;i*i<=ans;i++)
		{
            if(ans%i==0)
			{
                if(find(v.begin(),v.end(),i)==v.end()||find(v.begin(),v.end(),ans/i)==v.end()){flag=0;break;}
                sum+=2;
                if(i*i==ans)
                    sum--;
            }
        }
        if(sum==n&&flag==1)
            cout<<ans<<endl;
        else
            cout<<-1<<endl;
    }
    return 0;
}

E Two Arrays and Sum of Functions
You are given two arrays a and b, both of length n.

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

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

Input
The first line of the input contains one integer n (1≤n≤2⋅105) — the number of elements in a and b.

The second line of the input contains n integers a1,a2,…,an (1≤ai≤106), where ai is the i-th element of a.

The third line of the input contains n integers b1,b2,…,bn (1≤bj≤106), where bj is the j-th element of b.

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

Examples
Input
5
1 8 7 2 4
9 7 2 9 3
Output
646
Input
1
1000000
1000000
Output
757402647
Input
2
1 3
4 2
Output
20
这个题更感觉是个找规律的题目。因为对于a数组来说,它的贡献的价值和它的位置有关。而位置直接关系到次数的大小。打个表找规律,找出位置和次数的关系。然后正反排序。注意取余是对最后的答案取余,不要在中间的时候取余。
代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define ll long long
using namespace std;

const int maxx=2e5+100;
const int mod=998244353;
ll a[maxx];
ll b[maxx];
ll c[maxx];
ll num[maxx];
int n;

bool cmp(const ll x,const ll y)
{
	return x>y;
}

int main()
{
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=1;i<=n;i++) scanf("%I64d",&a[i]);
		for(int i=1;i<=n;i++) scanf("%I64d",&b[i]);
		if(n&1)
		{
			ll x=n-2;
			for(int i=1;i<=n/2+1;i++)
			{
				if(i==1) num[i]=n;
				else num[i]=num[i-1]+x,x-=2;
			}
			x=1;
			for(int i=n/2+2;i<=n;i++)
			{
				num[i]=num[i-1]-x,x+=2;
			}
		}
		else
		{
			ll x=n-2;
			for(int i=1;i<=n/2;i++)
			{
				if(i==1) num[i]=n;
				else num[i]=num[i-1]+x,x-=2;
			}
			num[n/2+1]=num[n/2];
			x=2;
			for(int i=n/2+2;i<=n;i++)
			{
				num[i]=num[i-1]-x,x+=2;
			}
		}
		for(int i=1;i<=n;i++) 
		{
			c[i]=num[i]*a[i];
		}
		sort(c+1,c+1+n,cmp);
		sort(b+1,b+1+n);
		ll ans=0;
		for(int i=1;i<=n;i++)
		{
			c[i]%=mod;
			ans=(ans+c[i]*b[i]%mod)%mod;
		}
		cout<<ans<<endl; 
	}
}

努力加油a啊,(o)/~

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值