Codeforces Round #553 (Div. 2)

A. Maxim and Biology

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Today in the scientific lyceum of the Kingdom of Kremland, there was a biology lesson. The topic of the lesson was the genomes. Let's call the genome the string "ACTG".

Maxim was very boring to sit in class, so the teacher came up with a task for him: on a given string ss consisting of uppercase letters and length of at least 44, you need to find the minimum number of operations that you need to apply, so that the genome appears in it as a substring. For one operation, you can replace any letter in the string ss with the next or previous in the alphabet. For example, for the letter "D" the previous one will be "C", and the next — "E". In this problem, we assume that for the letter "A", the previous one will be the letter "Z", and the next one will be "B", and for the letter "Z", the previous one is the letter "Y", and the next one is the letter "A".

Help Maxim solve the problem that the teacher gave him.

A string aa is a substring of a string bb if aa can be obtained from bb by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

Input

The first line contains a single integer nn (4≤n≤504≤n≤50) — the length of the string ss.

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

Output

Output the minimum number of operations that need to be applied to the string ss so that the genome appears as a substring in it.

Examples

input

Copy

4
ZCTH

output

Copy

2

input

Copy

5
ZDATG

output

Copy

5

input

Copy

6
AFBAKC

output

Copy

16

Note

In the first example, you should replace the letter "Z" with "A" for one operation, the letter "H" — with the letter "G" for one operation. You will get the string "ACTG", in which the genome is present as a substring.

In the second example, we replace the letter "A" with "C" for two operations, the letter "D" — with the letter "A" for three operations. You will get the string "ZACTG", in which there is a genome.

题目大意:

给你一个字符串,让你把他的一个子串变成ACTG,最少需要多少步(A->B为一步,A->Z为一步)

遍历字符串一个一个的改就行,刚开始觉得这个题很麻烦没做 然后被李先生怼了o(╥﹏╥)o,AC后,他又嘲笑我的代码太过于面向过程惹,嘤嘤嘤(╥╯^╰╥),做个可爱的小仙女怎么这么难...

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
#define ll long long
int n;
string s;
int Min=0x33f3f3f3f;

//ACTG
int Solve(int cur)
{
    int step=0;
    step+=min(abs(s[cur]-'A'),min('Z'-s[cur]+'A'-64,'Z'-'A'+s[cur]-64));
    //两个之间直接距离 经过Z转折
    step+=min(abs(s[cur+1]-'C'),min('Z'-s[cur+1]+'C'-64,'Z'-'C'+s[cur+1]-64));
    step+=min(abs(s[cur+2]-'T'),min('Z'-s[cur+2]+'T'-64,'Z'-'T'+s[cur+2]-64));
    step+=min(abs(s[cur+3]-'G'),min('Z'-s[cur+3]+'G'-64,'Z'-'G'+s[cur+3]-64));
    return step;
}
int main()
{
    cin>>n>>s;
    for(int i=0;i<=n-4;i++)//保证至少有4个字母
        Min=min(Min,Solve(i));

    cout<<Min<<endl;
}

B. Dima and a Bad XOR

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Student Dima from Kremland has a matrix aa of size n×mn×m filled with non-negative integers.

He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zero. Help him!

Formally, he wants to choose an integers sequence c1,c2,…,cnc1,c2,…,cn (1≤cj≤m1≤cj≤m) so that the inequality a1,c1⊕a2,c2⊕…⊕an,cn>0a1,c1⊕a2,c2⊕…⊕an,cn>0holds, where ai,jai,j is the matrix element from the ii-th row and the jj-th column.

Here x⊕yx⊕y denotes the bitwise XOR operation of integers xx and yy.

Input

The first line contains two integers nn and mm (1≤n,m≤5001≤n,m≤500) — the number of rows and the number of columns in the matrix aa.

Each of the next nn lines contains mm integers: the jj-th integer in the ii-th line is the jj-th element of the ii-th row of the matrix aa, i.e. ai,jai,j (0≤ai,j≤10230≤ai,j≤1023).

Output

If there is no way to choose one integer from each row so that their bitwise exclusive OR is strictly greater than zero, print "NIE".

Otherwise print "TAK" in the first line, in the next line print nn integers c1,c2,…cnc1,c2,…cn (1≤cj≤m1≤cj≤m), so that the inequality a1,c1⊕a2,c2⊕…⊕an,cn>0a1,c1⊕a2,c2⊕…⊕an,cn>0 holds.

If there is more than one possible answer, you may output any.

Examples

input

Copy

3 2
0 0
0 0
0 0

output

Copy

NIE

input

Copy

2 3
7 7 7
7 7 10

output

Copy

TAK
1 3 

Note

In the first example, all the numbers in the matrix are 00, so it is impossible to select one number in each row of the table so that their bitwise exclusive OR is strictly greater than zero.

In the second example, the selected numbers are 77 (the first number in the first line) and 1010 (the third number in the second line), 7⊕10=137⊕10=13, 1313 is more than 00, so the answer is found.

这道题我好像想的太麻烦的,在这里十分感谢李先生贡献的思路 (对8起,是我太菜了o(╥﹏╥)o

可以用unique把每一行去一下重(unique使用的前提是数组要有序的!所以要另开一个数组先排一下序,再去重!)然后标记一下去完重后最大的数组的元素个数,因为这里要判断可不可以异或为0,当去完重后每一行都是一个数,并且这些数的异或为0,那肯定就NIF了。如果异或不为0 ,那就遍历原数组找到这些数的位置输出就可以了。如果异或为0,但某行元素个数不是1,那把这一行的异或的数换为另一个,异或肯定不为0了

#include<bits/stdc++.h>
using namespace std;
const int maxn=500+5;
#define ll long long
int a[maxn][maxn];
int b[maxn][maxn];

int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            scanf("%d",&a[i][j]);
            b[i][j]=a[i][j];
        }
    }
    for(int i=0;i<n;i++)
        sort(b[i],b[i]+m);
    int Max=0,flag=0;
    for(int i=0;i<n;i++)
    {
        if(unique(b[i],b[i]+m)-b[i]>Max)
        {
            Max=unique(b[i],b[i]+m)-b[i];//去重后行最大元素个数
            flag=i;//第i行
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
        ans^=b[i][0];
    if(ans==0&&Max==1)//异或肯定为0
        printf("NIE\n");
    else
    {
        printf("TAK\n");
        if(ans!=0)//异或不为0
        {
            for(int i=0;i<n;i++)//遍历数组找数的位置
            {
                for(int j=0;j<m;j++)
                {
                    if(a[i][j]==b[i][0])
                    {
                        printf("%d ",j+1);
                        break;
                    }
                }
            }
        }
        else if(ans==0&&Max>1)//当前异或为0,换一个数 异或肯定不为0
        {
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)
                {
                    if(i==flag)//在元素最多的行里找
                    {
                        if(a[i][j]==b[i][1])//不再用这一行的第一个 改成用第二个
                        {
                            printf("%d ",j+1);
                            break;
                        }
                    }
                    else
                    {
                        if(a[i][j]==b[i][0])
                        {
                            printf("%d ",j+1);
                            break;
                        }
                    }
                }
            }
        }
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值