Codeforces Round #276 (Div. 2)

Source: Internet
Author: User

Codeforces Round #276 (Div. 2)

 


 

 

A. Factory time limit per test 1 second memory limit per test 256 megabytes

One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there wereXDetails in the factory storage, then by the end of the day the factory has to produce (remainder after dividingXByM) More details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory.

The board of directors are worried that the production by the given plan may eventually stop (that means that there will be executed moment when the current number of details on the factory is divisibleM).

Given the number of detailsAOn the first day and numberMCheck if the production stops at some moment.

Input

The first line contains two integersAAndM(1 digit ≤ DigitA, Bytes,MLimit ≤ limit 105 ).

Output

Print Yes (without quotes) if the production will eventually stop, otherwise print No.

Sample test (s) Input
1 5
Output
No
Input
3 6
Output
Yes

 

 

X adds the modulo value for m each time. If the modulo value is 0, YES is output. If the modulo value has appeared before, No is output and No is exited.

 

 

#include 
 
  #include 
  
   int vis[100002];int main(){int a, m;scanf(%d %d, &a, &m);memset(vis, 0, sizeof(vis));while(true){if(a == 0){printf(Yes);return 0;}if(vis[a]){printf(No);return 0;}vis[a] = 1;a = (a + a % m) % m;}}
  
 

 

 

 

 

 

 

B. Valuable ResourcesTime limit per test 1 second memory limit per test 256 megabytes

Compute computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.

Let's suppose that your task is to build a square city. the world map uses the Cartesian coordinates. the sides of the city shocould be parallel to coordinate axes. the map contains mines with valuable resources, located at some points with integer coordinates. the sizes of mines are relatively small, I. e. they can be treated as points. the city shoshould be built in such a way that all the mines are inside or on the border of the city square.

Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. given the positions of the mines find the minimum possible area of the city.

Input

The first line of the input contains numberN-The number of mines on the map (2 rows ≤ minuteNLimit ≤00001000). Each of the nextNLines contains a pair of integersXIAndYI-The coordinates of the corresponding mine (response-Timeout 109 bytes ≤ bytesXI, Bytes,YILimit ≤ limit 109). All points are pairwise distinct.

Output

Print the minimum area of the city that can cover all the mines with valuable resources.

Sample test (s) Input
20 02 2
Output
4
Input
20 00 3
Output
9

 

 

For a few vertices, place these vertices on or inside a square, and calculate the minimum value of the square area. The Top minus the bottom and the rightmost minus the leftmost value is used as the edge length.

 

 

#include 
 
  #include #define ll long longusing namespace std;int main(){int n;ll x, y;ll mu, md, ml, mr;ll ans = 0;mu = mr = -2147483646;ml = md = 2147483647;scanf(%d, &n);for(int i = 0; i < n; i++){scanf(%I64d %I64d, &x, &y);mu = max(mu , y);md = min(md , y);ml = min(ml , x);mr = max(mr , x);}ans = max((mu - md), (mr - ml)) * max((mu - md), (mr - ml));printf(%I64d, ans);}
 

 

 

 

 

 

 

 

C. BitsTime limit per test 1 second memory limit per test 256 megabytes

Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integerX.

You are given multiple queries consisting of pairs of integersLAndR. For each query, findX, Such thatLLimit ≤ limitXLimit ≤ limitR, And is maximum possible. If there are multiple such numbers find the smallest of them.

Input

The first line contains integerN-The number of queries (1 limit ≤ limitNLimit ≤ limit 10000 ).

Each of the followingNLines contain two integersLI, Bytes,RI-The arguments for the corresponding query (0 records ≤ limitLILimit ≤ limitRILimit ≤ limit 1018 ).

Output

For each query print the answer in a separate line.

Sample test (s) Input
31 22 41 10
Output
137
Note

The binary representations of numbers from 1 to 10 are listed below:

110 rows = Limit 12

210 bytes = average 102

310 rows = Limit 112

410 bytes = average 1002

510 bytes = average 1012

610 bytes = average 1102

710 bytes = average 1112

810 bytes = average 10002

910 bytes = average 10012

1010 bytes = average 10102

 

 

For an interval, convert the number in the interval to the one with the largest number of '1' after being binary. If the number of '1' is the same, the minimum number is used to output the data.

Directly perform the or operation on 1 from the left endpoint to construct the maximum and minimum number of '1' until the value is greater than the right endpoint.

 

 

#include 
 
  #define ll long longint main(){int t;    scanf(%d, &t);      while(t--)    {          ll l, r, tmp, p = 1;           scanf(%I64d %I64d, &l, &r);        for(ll i = 0; i < 63; i++)          {              ll tmp = l | p;             if(tmp > r)            break;              l = tmp;            p <<= 1;          }          printf(%I64d, l);    }  }
 

 

 

 

 

 

 

D. Maximum ValueTime limit per test 1 second memory limit per test 256 megabytes

You are given a sequenceAConsistingNIntegers. Find the maximum possible value of (integer remainderAIDividedAJ), Where1 limit ≤ limitI, Bytes,JLimit ≤ limitNAndAILimit ≥ limitAJ.

Input

The first line contains integerN-The length of the sequence (1 sequence ≤ sequenceNLimit ≤ limit 2 · 105 ).

The second line containsNSpace-separated integersAI(1 digit ≤ DigitAILimit ≤ limit 106 ).

Output

Print the answer to the problem.

Sample test (s) Input
33 4 5
Output
2

 

 

Find the maximum value of a [I] <a [j] a [j] % a [I]. The range of ai is small. Use hash to do this.

 

 

#include 
 
    int const MAX = 2000000 + 10;  int a[MAX];  int main()  {      int n, x, ans = 0;      scanf(%d,&n);        for(int i = 0; i < n; i++)      {          scanf(%d,&x);          a[x] = x;      }      for(int i = 0; i < MAX; i++)          if(a[i] != i)              a[i] = a[i - 1];      for(int i = 2; i < MAX; i++)            if(a[i] == i)              for(int j = i + i - 1; j < MAX; j = j + i)                  if(a[j] % i > ans && a[j] > i)                      ans = a[j] % i;            printf(%d,ans);   } 
 


 

 

 

 

 

Div.1: D. KindergartenTime limit per test 2 seconds memory limit per test 256 megabytes

In a kindergarten, the children are being divided into groups. the teacher put the children in a line and associated each child with his or her integer charisma value. each child shoshould go to exactly one group. each group shoshould be a nonempty segment of consecutive children of a line. A group's sociability is the maximum difference of charisma of two children in the group (in particle, if the group consists of one child, its sociability equals a zero ).

The teacher wants to divide the children into some number of groups in such way that the totalsociability of the groups is maximum. Help him find this value.

Input

The first line contains integerN-The number of children in the line (1 limit ≤ limitNLimit ≤ limit 106 ).

The second line containsNIntegersAI-The charisma ofI-Th child (bytes-second 109 bytes ≤ bytesAILimit ≤ limit 109 ).

Output

Print the maximum possible total sociability of all groups.

Sample test (s) Input
51 2 3 1 2
Output
3
Input
33 3 3
Output
0
Note

In the first test sample one of the possible variants of an division is following: the first three children form a group with sociability 2, and the two remaining children form a group with sociability 1.

In the second test sample any division leads to the same result, the sociability will be equal to 0 in each group.

 

Divides a series into several groups. The weight of each group is the difference between the maximum value and the minimum value in the group.

 

 

#include 
 
  #define ll long longint main(){    int n, t;     scanf (%d, &n);    ll ans = 0, t1 = 0, t2 = 0;    for(int i = 0; i < n; i++)    {        scanf(%d, &t);        if (!i || ans + t > t1) t1 = ans + t;        if (!i || ans - t > t2) t2 = ans - t;        ans = t1 - t > t2 + t ? t1 - t : t2 + t;    }    printf(%I64d, ans);}
 


 


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.