Codeforces Round #472 (rated, Div. 2, based on VK Cup 2018 Round 2)题解

A. Tritonic Iridescence
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.

Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into nconsecutive segments, each segment needs to be painted in one of the colours.

Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them.

Input

The first line contains a single positive integer n (1 ≤ n ≤ 100) — the length of the canvas.

The second line contains a string s of n characters, the i-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one).

Output

If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes).

You can print each character in any case (upper or lower).

#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include <set>
#include <stack>
#include <map>
#include<vector>
#include <iterator>
#define INF 0x3f3f3f3f

using namespace std;
const int MAXN = 101000;
char c[110];
int num = 0;
int n;
bool Judge()
{
    for(int i =0 ;i < n;i ++)
    {
        if(c[i] == '?')
        {
            if(i == 0 || i == n-1)
                return false;
            else if(c[i- 1] == '?' || c[i+1] == '?' || c[i-1] == c[i+1])
                return false;
        }
    }
    return true;
}
bool Already()
{
    for(int i = 1;i <n;i ++)
        if(c[i] == c[i-1] && c[i]!='?')
        return true;
    return false;
}
int main()
{
    while(~scanf("%d",&n))
    {
        num = 0;
        scanf("%s",c);
        for(int i = 0;i < n;i ++)
        {
            if(c[i] == '?')
                num ++;
        }
        if(num ==0 || Judge()||Already() )
        {
            printf("No\n");
        }
        else
        {
            printf("Yes\n");
        }
    }


}
B. Mystical Mosaic
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a rectangular grid of n rows of m initially-white cells each.

Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.

There's another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i < j) exists such that  or , where  denotes intersection of sets, and  denotes the empty set.

You are to determine whether a valid sequence of operations exists that produces a given final grid.

Input

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.

Each of the following n lines contains a string of m characters, each being either '.' (denoting a white cell) or '#' (denoting a black cell), representing the desired setup.

Output

If the given grid can be achieved by any valid sequence of operations, output "Yes"; otherwise output "No" (both without quotes).

You can print each character in any case (upper or lower).



#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include <set>
#include <stack>
#include <map>
#include<vector>
#include <iterator>
#define INF 0x3f3f3f3f

using namespace std;
const int MAXN = 55;
int n,m;
set<string> str;
string s;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m;
    for(int i = 0;i < n;i ++)
    {
        cin>>s;
        str.insert(s);
    }
    set<string>::iterator it = str.begin();
    string mapp[MAXN];
    int index = 0;
    for(;it != str.end();it ++)
    {
        mapp[index++] = *it;
    }
//    for(int i = 0;i < index;i ++)
//        cout<<mapp[i]<<endl;
    for(int i = 0;i < m;i ++)
    {
        int ans = 0;
        for(int j = 0;j < index;j ++)
        {
            if(mapp[j][i] == '#')
                ans++;
        }
        if(ans >= 2)
        {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}
C. Three-level Laser
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

An atom of element X can exist in n distinct states with energies E1 < E2 < ... < En. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.

Three distinct states ij and k are selected, where i < j < k. After that the following process happens:

  1. initially the atom is in the state i,
  2. we spend Ek - Ei energy to put the atom in the state k,
  3. the atom emits a photon with useful energy Ek - Ej and changes its state to the state j,
  4. the atom spontaneously changes its state to the state i, losing energy Ej - Ei,
  5. the process repeats from step 1.

Let's define the energy conversion efficiency as , i. e. the ration between the useful energy of the photon and spent energy.

Due to some limitations, Arkady can only choose such three states that Ek - Ei ≤ U.

Help Arkady to find such the maximum possible energy conversion efficiency within the above constraints.

Input

The first line contains two integers n and U (3 ≤ n ≤ 1051 ≤ U ≤ 109) — the number of states and the maximum possible difference between Ek and Ei.

The second line contains a sequence of integers E1, E2, ..., En (1 ≤ E1 < E2... < En ≤ 109). It is guaranteed that all Ei are given in increasing order.

Output

If it is not possible to choose three states that satisfy all constraints, print -1.

Otherwise, print one real number η — the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10 - 9.

Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if .



#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include <set>
#include <stack>
#include <map>
#include<vector>
#include <iterator>
#define INF 0x3f3f3f3f
#define ll long long

using namespace std;
const int MAXN = 101000;
ll n,U;
ll a[MAXN];

int get_pos(int p,int M)
{
//二分优化,否则会卡在第11组数据......
    if(a[n] < a[p]+ M)
        return n+1;
    int l = p,r = n;
    while(l <= r)
    {
        int mid = (l+r) >> 1;
        if(a[mid] > a[p] + M)
            r = mid-1;
        else
            l = mid+1;
    }
    return l;
}
int main()
{
    while(~scanf("%I64d%I64d",&n,&U))
    {
        double max_ans = -1*INF;
        for(int i = 1;i <= n;i ++)
            scanf("%I64d",&a[i]);
        for(int i = 1;i <= n-2;i ++)
        {
            int pos = get_pos(i,U)-1;
            if(pos - i >= 2)
                max_ans = max(max_ans,double(a[pos] - a[i+1])/double(a[pos] - a[i]));
        }
        if(max_ans == -1 * INF)
            printf("-1\n");
        else
            printf("%.10lf\n",max_ans);

    }
}
D. Riverside Curio
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value.

Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water does not wash the marks away. Arkady writes down the number of marks strictly above the water level each day, on the i-th day this value is equal to mi.

Define di as the number of marks strictly under the water level on the i-th day. You are to find out the minimum possible sum of di over all days. There are no marks on the channel before the first day.

Input

The first line contains a single positive integer n (1 ≤ n ≤ 105) — the number of days.

The second line contains n space-separated integers m1, m2, ..., mn (0 ≤ mi < i) — the number of marks strictly above the water on each day.

Output

Output one single integer — the minimum possible sum of the number of marks strictly below the water level among all days.

//不怕别人比你聪明,就怕别人比你聪明还比你努力
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include <set>
#include <stack>
#include <map>
#include<vector>
#include <iterator>
#define INF 0x3f3f3f3f
#define ll long long

using namespace std;
const int MAXN = 101000;
int n;
ll a[MAXN];
int num[MAXN];
ll ans;

int main()
{
    while(~scanf("%d",&n))
    {
        memset(num,0,sizeof(num));
        ans = 0;
        int max_leve = INF * -1;
        int max_pos = -1;
        for(int i =0 ;i < n;i++)
        {
            scanf("%I64d",&a[i]);
            num[i] = a[i];
            if(a[i] > max_leve)
            {
                max_leve = a[i];
                max_pos = i;
            }
        }
        int now_leve = 0;
        for(int i =1;i <= max_pos;i++)//首先是在只考虑自己和前面的情况下,这个位置上最少有几个
        {
            num[i] = max(num[i],num[i-1]);
        }
        for(int i = max_pos;i >= 1;i --)
        {
            if(num[i] - num[i-1] >= 2)//我们发现当两个痕之间的差值大于2的话,我们那么前面的最少的
                //痕迹就是后面痕迹的减1
            {
                num[i-1] = num[i] -1;
            }
        }
        for(int i = 1;i < max_pos;i ++)
            ans += num[i] - a[i];
        //在最大值后面的痕迹树已经确定了,所以就可以直接确定结果了
        for(int i = max_pos+1 ;i< n;i++)
        {
            ans += max_leve - a[i];
        }
        printf("%I64d\n",ans);

    }
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值