A. Link/Cut Tree
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.

Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)

Given integers lr and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!

Input

The first line of the input contains three space-separated integers lr and k (1 ≤ l ≤ r ≤ 1018, 2 ≤ k ≤ 109).

Output

Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).

Sample test(s)
input
1 10 2
output
1 2 4 8 
input
2 4 5
output
-1
Note

Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed.

 #include <bits/stdc++.h>
using namespace std; int main()
{
long long l,r,k,m;
scanf("%I64d %I64d %I64d",&l,&r,&k);
if(k==)
{
if(k<=r && k>=l)
printf("1\n");
else
printf("-1\n");
}
else
{
m=;
int flg=;
while(m<=r)
{
if(m>=l)
{
if(flg==)
printf("%I64d",m);
else
printf(" %I64d",m);
flg=;
}
if(r/m<k)
break;
m=m*k;
}
if(flg==)
printf("-1");
printf("\n");
}
}
                B. Gena's Code
time limit per test

0.5 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse!

There are exactly n distinct countries in the world and the i-th country added ai tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful.

Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case.

Input

The first line of the input contains the number of countries n (1 ≤ n ≤ 100 000). The second line contains n non-negative integers aiwithout leading zeroes — the number of tanks of the i-th country.

It is guaranteed that the second line contains at least n - 1 beautiful numbers and the total length of all these number's representations doesn't exceed 100 000.

Output

Print a single number without leading zeroes — the product of the number of tanks presented by each country.

Sample test(s)
input
3
5 10 1
output
50
input
4
1 1 10 11
output
110
input
5
0 3 1 100 1
output
0
Note

In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.

In sample 2 number 11 is not beautiful (contains two '1's), all others are beautiful.

In sample 3 number 3 is not beautiful, all others are beautiful.

 #include <bits/stdc++.h>
using namespace std; char a[],b[];
int num; int check()
{
int i,j,k=;
for(i=;i<strlen(a);i++)
{
if(a[i]=='' || a[i]=='')
{
if(a[i]=='')
k++;
if(k>)
return ;
}
else
return ;
}
return ;
} void cal()
{
num=num+strlen(a)-;
return ;
} int main()
{
int n,flg=;
int i,j,k;
int ch=;
num=;b[]='';
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%s",a);
if(a[]=='')
{
flg=;
}
if(flg==)
{
if(ch==)
{
if(check()==)
{
strcpy(b,a);
ch=;
continue;
}
}
cal();
}
} if(flg==)
{
printf("0\n");
return ;
}
printf("%s",b);
for(i=;i<=num;i++)
printf("");
printf("\n");
return ;
}
                C. Peter and Snow Blower
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it will go along a circle around this point and will remove all the snow from its path.

Formally, we assume that Peter's machine is a polygon on a plane. Then, after the machine is switched on, it will make a circle around the point to which Peter tied it (this point lies strictly outside the polygon). That is, each of the points lying within or on the border of the polygon will move along the circular trajectory, with the center of the circle at the point to which Peter tied his machine.

Peter decided to tie his car to point P and now he is wondering what is the area of ​​the region that will be cleared from snow. Help him.

Input

The first line of the input contains three integers — the number of vertices of the polygon n (), and coordinates of point P.

Each of the next n lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices lie on a common straight line.

All the numbers in the input are integers that do not exceed 1 000 000 in their absolute value.

Output

Print a single real value number — the area of the region that will be cleared. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.

Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

Sample test(s)
input
3 0 0
0 1
-1 2
1 2
output
12.566370614359172464
input
4 1 -1
0 0
1 2
2 0
1 1
output
21.991148575128551812
Note

In the first sample snow will be removed from that area:

                D. Skills
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer ai — the current skill level. All skills have the same maximum level A.

Along with the skills, global ranking of all players was added. Players are ranked according to the so-called Force. The Force of a player is the sum of the following values:

  • The number of skills that a character has perfected (i.e., such that ai = A), multiplied by coefficient cf.
  • The minimum skill level among all skills (min ai), multiplied by coefficient cm.

Now Lesha has m hacknetian currency units, which he is willing to spend. Each currency unit can increase the current level of any skill by 1 (if it's not equal to A yet). Help him spend his money in order to achieve the maximum possible value of the Force.

Input

The first line of the input contains five space-separated integers nAcfcm and m (1 ≤ n ≤ 100 000, 1 ≤ A ≤ 109, 0 ≤ cf, cm ≤ 1000,0 ≤ m ≤ 1015).

The second line contains exactly n integers ai (0 ≤ ai ≤ A), separated by spaces, — the current levels of skills.

Output

On the first line print the maximum value of the Force that the character can achieve using no more than m currency units.

On the second line print n integers a'i (ai ≤ a'i ≤ A), skill levels which one must achieve in order to reach the specified value of the Force, while using no more than m currency units. Numbers should be separated by spaces.

Sample test(s)
input
3 5 10 1 5
1 3 1
output
12
2 5 2
input
3 5 10 1 339
1 3 1
output
35
5 5 5
Note

In the first test the optimal strategy is to increase the second skill to its maximum, and increase the two others by 1.

In the second test one should increase all skills to maximum.

 #include <bits/stdc++.h>
using namespace std; struct Node
{
int v;
int id;
}a[];
long long sum[];
bool cmp(Node x,Node y)
{
return x.v<y.v;
} bool anothercmp(Node x,Node y)
{
return x.id<y.id;
} int main()
{
int i,j;
int n,Cf,Cm;
long long A,m;
while(~scanf("%d%I64d%d%d%I64d",&n,&A,&Cf,&Cm,&m)){
for(i=;i<=n;i++)
{
scanf("%d",&a[i].v);
a[i].id=i;
}
sort(a+,a+n+,cmp);
sum[]=;
for(i=;i<=n;i++)
{
sum[i]=sum[i-]+a[i].v;
}
long long ans=-,ansi,ansj,ansmi;
long long cost,remin,tmi,force;
for(i=,j=;i<=n;i++)
{
cost=A*(n-i)-(sum[n]-sum[i]);
if(cost>m)
continue;
remin=m-cost;
while(j<=i && (1ll*a[j].v*j-sum[j])<=remin)
{
j++;
}
j--;
if(i==)
{
tmi=A;
}
else
{
tmi=min((remin+sum[j])/j,A);
}
force=1ll*(n-i)*Cf+1ll*tmi*Cm;
if(force>ans)
{
ans=force;
ansi=i;
ansj=j;
ansmi=tmi;
}
} for(i=;i<=ansj;i++)
{
a[i].v=ansmi;
}
for(i=ansi+;i<=n;i++)
{
a[i].v=A;
}
sort(a+,a+n+,anothercmp);
printf("%I64d\n",ans); for(i=;i<=n;i++)
{
printf("%d ",a[i].v);
}
printf("\n"); }
return ;
}
 
                E. Necklace
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Ivan wants to make a necklace as a present to his beloved girl. A necklace is a cyclic sequence of beads of different colors. Ivan says that necklace is beautiful relative to the cut point between two adjacent beads, if the chain of beads remaining after this cut is a palindrome (reads the same forward and backward).

Ivan has beads of n colors. He wants to make a necklace, such that it's beautiful relative to as many cuts as possible. He certainly wants to use all the beads. Help him to make the most beautiful necklace.

Input

The first line of the input contains a single number n (1 ≤ n ≤ 26) — the number of colors of beads. The second line contains after npositive integers ai   — the quantity of beads of i-th color. It is guaranteed that the sum of ai is at least 2 and does not exceed 100 000.

Output

In the first line print a single number — the maximum number of beautiful cuts that a necklace composed from given beads may have. In the second line print any example of such necklace.

Each color of the beads should be represented by the corresponding lowercase English letter (starting with a). As the necklace is cyclic, print it starting from any point.

Sample test(s)
input
3
4 2 1
output
1
abacaba
input
1
4
output
4
aaaa
input
2
1 1
output
0
ab
Note

In the first sample a necklace can have at most one beautiful cut. The example of such a necklace is shown on the picture.

In the second sample there is only one way to compose a necklace.

 #include <bits/stdc++.h>
using namespace std; int gcd(int x,int y)
{
if(x<y)
return gcd(y,x);
else if(y==)
return x;
else
return gcd(y,x%y);
} int a[]; int main()
{
int n,g;
int i,j,k,oddnum=;
scanf("%d",&n);
for(i=;i<=n;i++)
{
scanf("%d",&a[i]);
if(a[i]%!=)
{
oddnum++;
k=i;
}
} if(n==)
{
printf("%d\n",a[]);
while(a[]--) printf("%c",+);
printf("\n");
return ;
}
if(oddnum>)
{
printf("0\n");
for(i=;i<=n;i++)
{
for(j=;j<=a[i];j++)
printf("%c",i+);
}
printf("\n");
}
else
{
g=a[];
for(i=;i<=n;i++)
{
g=gcd(g,a[i]);
}
printf("%d\n",g);int h=g; if(g%==)
{
while(h--)
{
for(i=;i<=n;i++)
{
if(i!=k)
for(j=;j<=a[i]/(g*);j++)
{
printf("%c",i+);
}
}
for(j=;j<=a[k]/g;j++)
printf("%c",k+);
for(i=n;i>=;i--)
{
if(i!=k)
for(j=;j<=a[i]/(g*);j++)
{
printf("%c",i+);
}
}
}
printf("\n");
}
else
{ int flg=;
while(h--)
{
if(flg==)
{
flg=;
for(i=;i<=n;i++)
{
for(j=;j<=a[i]/g;j++)
{
printf("%c",i+);
}
}
}
else
{
flg=;
for(i=n;i>=;i--)
{
for(j=;j<=a[i]/g;j++)
{
printf("%c",i+);
}
}
}
}
printf("\n");
}
}
}

Codeforces Round #339 (Div.2)的更多相关文章

  1. Codeforces Round #339 (Div. 1) A. Peter and Snow Blower 计算几何

    A. Peter and Snow Blower 题目连接: http://www.codeforces.com/contest/613/problem/A Description Peter got ...

  2. Codeforces Round #339 (Div. 2) B. Gena's Code 水题

    B. Gena's Code 题目连接: http://www.codeforces.com/contest/614/problem/B Description It's the year 4527 ...

  3. Codeforces Round #339 (Div. 2) A. Link/Cut Tree 水题

    A. Link/Cut Tree 题目连接: http://www.codeforces.com/contest/614/problem/A Description Programmer Rostis ...

  4. Codeforces Round #339 (Div. 1) C. Necklace 构造题

    C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...

  5. Codeforces Round #339 (Div. 1) B. Skills 暴力 二分

    B. Skills 题目连接: http://www.codeforces.com/contest/613/problem/B Description Lesha plays the recently ...

  6. Codeforces Round #339 Div.2 C - Peter and Snow Blower

    Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. A ...

  7. Codeforces Round #339 Div.2 B - Gena's Code

    It's the year 4527 and the tanks game that we all know and love still exists. There also exists Grea ...

  8. Codeforces Round #339 Div.2 A - Link/Cut Tree

    第一次正式参加常规赛想想有些小激动的呢 然后第一题就被hack了 心痛 _(:зゝ∠)_ tle点在于越界 因此结束循环条件从乘变为除 done //等等 这题没过总评 让我静静........ // ...

  9. Codeforces Round #339 (Div. 2) A

    Description Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which ...

随机推荐

  1. IOS第18天(1,核心动画layer, 旋转,缩放,平移,边框,剪裁,圆角)

    ****动画效果 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [UIView animateWithDurat ...

  2. (三)CMS Collector

    有些资料中,为区别parallel collector ,将应用与gc并发成为并行,在接下来的文章中,仍称为并发. -XX:useConcMarkSweepGC,可以用于minor gc和major ...

  3. Windows下获取本机IP地址方法介绍

    Windows下获取本机IP地址方法介绍 if((hostinfo = gethostbyname(name)) != NULL) { #if 1 ; printf("IP COUNT: % ...

  4. 分时间uu

    #include<stdio.h> int map[20][4]; typedef struct node{  int star;  int end; }node; node dui[10 ...

  5. UIView画虚线边框

    //fatherView加虚线边框 -(void)boundingRectangleForView:(UIView *)fatherView{ CAShapeLayer *borderLayer = ...

  6. 能套用的tab栏切换

    效果: 在style.js文件里封装了一个Show函数,有4个参数,di(当前点击的按钮),num(按钮个数,也可以说是下面具体内容个数),divn(一个id前缀,这个例子里是ta,),active( ...

  7. mvc 数据验证金钱格式decimal格式验证

    mvc 数据验证金钱格式decimal格式验证 首先看下代码 /// <summary> /// 产品单价 /// </summary> [Display(Name = &qu ...

  8. UE4 性能优化方法(工具篇)

    本文依据UE4官方文档以及官方博客等总结而来,可能不全面,后面会陆续添加.内置工具的详细说明请参考官方文档. 游戏帧率很低,或者有卡顿的现象,可能会有很多原因,这时候不要乱猜,比如是不是人物太多了或者 ...

  9. nginx限制访问速度

    转自:http://siwei.me/blog/posts/nginx-ip 参考:http://tengine.taobao.org/document_cn/http_limit_req_cn.ht ...

  10. 父目录的权限对子目录有没有影响?[Linux]

    问题源头: 登录到服务器(实验室分的一个服务器账号)上,想在当前目录下创建一个文件,但提示“文件系统只读”,无法创建文件.通过ls -l 查看当前用户在当前目录的权限,发现具有rwx权限.所以在想会不 ...