Codeforces Round #379 (Div. 2) A B C D

A. Anton and Danik
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Anton likes to play chess, and so does his friend Danik.

Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.

Now Anton wonders, who won more games, he or Danik? Help him determine this.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of games played.

The second line contains a string s, consisting of n uppercase English letters 'A' and 'D' — the outcome of each of the games. The i-th character of the string is equal to 'A' if the Anton won the i-th game and 'D' if Danik won the i-th game.

Output

If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.

If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.

If Anton and Danik won the same number of games, print "Friendship" (without quotes).

Examples
Input
6
ADAAAA
Output
Anton
Input
7
DDDAADA
Output
Danik
Input
6
DADADA
Output
Friendship
Note

In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".

In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".

In the third sample, both Anton and Danik won 3 games and the answer is "Friendship".



SB题。
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pll;
typedef long long ll;
int main()
{
      int n;
      cin>>n;
      string s;
      cin>>s;
      int l=s.size();
      int a,b;
      a=b=0;
      for(int i=0;i<l;i++)
        if(s[i]=='A')
        a++;
        else
        b++;
        if(a>b)
        puts("Anton");
        else if(a<b)
        puts("Danik");
        else
        puts("Friendship");
}












B. Anton and Digits
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Recently Anton found a box with digits in his room. There are k2 digits 2, k3 digits 3, k5 digits 5 and k6 digits 6.

Anton's favorite integers are 32 and 256. He decided to compose this integers from digits he has. He wants to make the sum of these integers as large as possible. Help him solve this task!

Each digit can be used no more than once, i.e. the composed integers should contain no more than k2 digits 2, k3 digits 3 and so on. Of course, unused digits are not counted in the sum.

Input

The only line of the input contains four integers k2, k3, k5 and k6 — the number of digits 2, 3, 5 and 6 respectively (0 ≤ k2, k3, k5, k6 ≤ 5·106).

Output

Print one integer — maximum possible sum of Anton's favorite integers that can be composed using digits from the box.

Examples
Input
5 1 3 4
Output
800
Input
1 1 1 1
Output
256
Note

In the first sample, there are five digits 2, one digit 3, three digits 5 and four digits 6. Anton can compose three integers 256 and one integer 32 to achieve the value 256 + 256 + 256 + 32 = 800. Note, that there is one unused integer 2 and one unused integer 6. They are not counted in the answer.

In the second sample, the optimal answer is to create on integer 256, thus the answer is 256



SB题,贪心选下就好了。
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pll;
typedef long long ll;
int main()
{
       ll a,b,c,d;
       cin>>a>>b>>c>>d;
       ll aa=min(a,c);
       ll bb=min(c,d);
       ll cc=min(aa,bb);
       ll sum=0;
       sum+=cc*256;
       a-=cc;
       c-=cc;
       d-=cc;
       ll bbb=min(a,b);
       sum+=32*bbb;
       cout<<sum<<endl;
}


















C. Anton and Making Potions
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare n potions.

Anton has a special kettle, that can prepare one potions in x seconds. Also, he knows spells of two types that can faster the process of preparing potions.

  1. Spells of this type speed up the preparation time of one potion. There are m spells of this type, the i-th of them costs bi manapoints and changes the preparation time of each potion to ai instead of x.
  2. Spells of this type immediately prepare some number of potions. There are k such spells, the i-th of them costs di manapoints and instantly create ci potions.

Anton can use no more than one spell of the first type and no more than one spell of the second type, and the total number of manapoints spent should not exceed s. Consider that all spells are used instantly and right before Anton starts to prepare potions.

Anton wants to get to the next level as fast as possible, so he is interested in the minimum number of time he needs to spent in order to prepare at least n potions.

Input

The first line of the input contains three integers n, m, k (1 ≤ n ≤ 2·109, 1 ≤ m, k ≤ 2·105) — the number of potions, Anton has to make, the number of spells of the first type and the number of spells of the second type.

The second line of the input contains two integers x and s (2 ≤ x ≤ 2·109, 1 ≤ s ≤ 2·109) — the initial number of seconds required to prepare one potion and the number of manapoints Anton can use.

The third line contains m integers ai (1 ≤ ai < x) — the number of seconds it will take to prepare one potion if the i-th spell of the first type is used.

The fourth line contains m integers bi (1 ≤ bi ≤ 2·109) — the number of manapoints to use the i-th spell of the first type.

There are k integers ci (1 ≤ ci ≤ n) in the fifth line — the number of potions that will be immediately created if the i-th spell of the second type is used. It's guaranteed that ci are not decreasing, i.e. ci ≤ cj if i < j.

The sixth line contains k integers di (1 ≤ di ≤ 2·109) — the number of manapoints required to use the i-th spell of the second type. It's guaranteed that di are not decreasing, i.e. di ≤ dj if i < j.

Output

Print one integer — the minimum time one has to spent in order to prepare n potions.

Examples
Input
20 3 2
10 99
2 4 3
20 10 40
4 15
10 80
Output
20
Input
20 3 2
10 99
2 4 3
200 100 400
4 15
100 800
Output
200
Note

In the first sample, the optimum answer is to use the second spell of the first type that costs 10 manapoints. Thus, the preparation time of each potion changes to 4 seconds. Also, Anton should use the second spell of the second type to instantly prepare 15 potions spending 80 manapoints. The total number of manapoints used is 10 + 80 = 90, and the preparation time is 4·5 = 20 seconds (15 potions were prepared instantly, and the remaining 5 will take 4 seconds each).

In the second sample, Anton can't use any of the spells, so he just prepares 20 potions, spending 10 seconds on each of them and the answer is 20·10 = 200.




注意到第二种方式的数组是递减的。复杂度则为O(nlog(n))

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pll;
typedef long long ll;
struct node
{
    ll fi,cost;
} f[300005],f1[300005];
bool cmp(node a,node b)
{
    return a.cost<b.cost;
}
int main()
{
    ll n,k,m;
    ll time,sum;
    int ok=0;
    cin>>n>>m>>k>>time>>sum;
    ll max1=1e18*4;
    for(int i=0; i<m; i++)  //改变时间
        cin>>f[i].fi;
    for(int i=0; i<m; i++)
    {
        cin>>f[i].cost;  //花费
        if(f[i].cost<=sum)
        {
            ok=1;
            max1=max(min(f[i].fi*n,max1),0LL);
        }
    }
    for(int i=0; i<k; i++)  //生产出f[i].sc
        cin>>f1[i].fi;
    for(int i=0; i<k; i++)
    {
        cin>>f1[i].cost;  //花费
        if(f1[i].cost<=sum)
        {
            ok=1;
            max1=max(min(time*(n-f1[i].fi),max1),0LL);
        }
    }
    sort(f,f+m,cmp);
    if(ok==0)
    {
        cout<<time*n<<endl;
    }
    else
    {
        int j=k-1;
        for(int i=0; i<m; i++)
        {
            ll ans=f[i].cost;
            while(ans+f1[j].cost>sum)j--;
            if(ans+f1[j].cost<=sum &&j>=0)
                max1=max(min(f[i].fi*(n-f1[j].fi),max1),0LL);
        }
        cout<<max1<<endl;
    }
}













D. Anton and Chess
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Anton likes to play chess. Also, he likes to do programming. That is why he decided to write the program that plays chess. However, he finds the game on 8 to 8 board to too simple, he uses an infinite one instead.

The first task he faced is to check whether the king is in check. Anton doesn't know how to implement this so he asks you to help.

Consider that an infinite chess board contains one white king and the number of black pieces. There are only rooks, bishops and queens, as the other pieces are not supported yet. The white king is said to be in check if at least one black piece can reach the cell with the king in one move.

Help Anton and write the program that for the given position determines whether the white king is in check.

Remainder, on how do chess pieces move:

  • Bishop moves any number of cells diagonally, but it can't "leap" over the occupied cells.
  • Rook moves any number of cells horizontally or vertically, but it also can't "leap" over the occupied cells.
  • Queen is able to move any number of cells horizontally, vertically or diagonally, but it also can't "leap".
Input

The first line of the input contains a single integer n (1 ≤ n ≤ 500 000) — the number of black pieces.

The second line contains two integers x0 and y0 ( - 109 ≤ x0, y0 ≤ 109) — coordinates of the white king.

Then follow n lines, each of them contains a character and two integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — type of the i-th piece and its position. Character 'B' stands for the bishop, 'R' for the rook and 'Q' for the queen. It's guaranteed that no two pieces occupy the same position.

Output

The only line of the output should contains "YES" (without quotes) if the white king is in check and "NO" (without quotes) otherwise.

Examples
Input
2
4 2
R 1 1
B 1 5
Output
YES
Input
2
4 2
R 3 3
B 1 5
Output
NO
Note

Picture for the first sample:

White king is in check, because the black bishop can reach the cell with the white king in one move. The answer is " YES".

Picture for the second sample:

Here bishop can't reach the cell with the white king, because his path is blocked by the rook, and the bishop cant "leap" over it. Rook can't reach the white king, because it can't move diagonally. Hence, the king is not in check and the answer is " NO".



也是傻逼题,记录八个方向离king最近的那个棋子。然后判断下就好。



#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pll;
typedef long long ll;
const int N=5*1e5+100;
char s[N][1];
ll x[N],y[N];
int main()
{
    int n;
    while(cin>>n)
    {
        ll kx,ky;
        cin>>kx>>ky;
        char str[8];
        ll op[8];
        for(int i=0; i<8; i++)
            op[i]=1LL*pow(2,63)-1;
        for(int i=0; i<n; i++)
        {
            cin>>s[i]>>x[i]>>y[i];
            if(y[i]==ky &&x[i]-kx<op[0] &&x[i]>kx)    //正右
            {
                op[0]=x[i]-kx;
                str[0]=s[i][0];
            }
            else if(y[i]>ky &&x[i]>kx  &&x[i]-kx==y[i]-ky &&pow(x[i]-kx,2)*2<op[1])
            {
                op[1]=pow(x[i]-kx,2)*2;
                str[1]=s[i][0];
            }
            else  if(x[i]==kx &&y[i]-ky<op[2] &&y[i]>ky)    //正上
            {
                op[2]=y[i]-ky;
                str[2]=s[i][0];
            }
            else if(y[i]>ky &&x[i]<kx  &&kx-x[i]==y[i]-ky &&pow(x[i]-kx,2)*2<op[3])
            {
                op[3]=pow(x[i]-kx,2)*2;
                str[3]=s[i][0];
            }
            else   if(y[i]==ky &&kx-x[i]<op[4] &&x[i]<kx)
            {
                op[4]=kx-x[i];
                str[4]=s[i][0];
            }
            else if(y[i]<ky &&x[i]<kx  &&x[i]-kx==y[i]-ky &&pow(x[i]-kx,2)*2<op[5])
            {
                op[5]=pow(x[i]-kx,2)*2;
                str[5]=s[i][0];
            }
            else  if(x[i]==kx &&ky-y[i]<op[6] &&y[i]<ky)
            {
                op[6]=ky-y[i];
                str[6]=s[i][0];
            }
            else if(y[i]<ky &&x[i]>kx  &&kx-x[i]==y[i]-ky &&pow(x[i]-kx,2)*2<op[7])
            {
                op[7]=pow(x[i]-kx,2)*2;
                str[7]=s[i][0];
            }
        }
        for(int i=0; i<8; i++)
        {
            if(op[i]!=1LL*pow(2,63)-1)
            {
                if(i==0  || i==2 || i==4 || i==6)
                {
                    if(str[i]=='R' ||str[i]=='Q')
                        return 0*puts("YES");
                }
                else
                {
                    if(str[i]=='B' ||str[i]=='Q')
                        return 0*puts("YES");
                }
            }
        }
        return 0*puts("NO");
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值