0
点赞
收藏
分享

微信扫一扫

AtCoder Regular Contest 069

天行五煞 2023-02-08 阅读 117


 

C - Scc Puzzle

Time Limit: 2 sec / Memory Limit: 256 MB

Score : 300300 points

Problem Statement

Snuke loves puzzles.

Today, he is working on a puzzle using ​​S​​​- and ​​c​​​-shaped pieces. In this puzzle, you can combine two ​​c​​​-shaped pieces into one ​​S​​-shaped piece, as shown in the figure below:

AtCoder Regular Contest 069_i++

Snuke decided to create as many ​​Scc​​​ groups as possible by putting together one ​​S​​​-shaped piece and two ​​c​​-shaped pieces.

Find the maximum number of ​​Scc​​​ groups that can be created when Snuke has NN ​​S​​​-shaped pieces and MM ​​c​​-shaped pieces.

Constraints

  • 1≤N,M≤10121≤N,M≤1012

Input

The input is given from Standard Input in the following format:


NN MM


Output

Print the answer.

Sample Input 1 Copy

Copy


1 6


Sample Output 1 Copy

Copy


2


Two ​​Scc​​ groups can be created as follows:

  • Combine two ​​c​​​-shaped pieces into one ​​S​​-shaped piece
  • Create two ​​Scc​​​ groups, each from one ​​S​​​-shaped piece and two ​​c​​-shaped pieces

Sample Input 2 Copy

Copy


12345 678901


Sample Output 2 Copy

Copy


175897


水题

#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
#define PI acos(-1.0)
#define MOD 2520
#define E 1e-12
using namespace std;
typedef long long ll;
const int MAXN=500000+5;//最大元素个数
ll n,m;
int main()
{
scanf("%lld%lld",&n,&m);
if(2*n>=m)
{
cout<<min(n,m/2)<<endl;
}
else
{
ll cha=m-2*n;
//cout<<2*n<<" "<<cha<<endl;
cout<<n+cha/4<<endl;
}


return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
#define PI acos(-1.0)
#define MOD 2520
#define E 1e-12
using namespace std;
typedef long long ll;
const int MAXN=500000+5;//最大元素个数
ll n,m;
int main()
{
scanf("%lld%lld",&n,&m);
if(2*n>=m)
{
cout<<min(n,m/2)<<endl;
}
else
{
ll cha=m-2*n;
//cout<<2*n<<" "<<cha<<endl;
cout<<n+cha/4<<endl;
}


return 0;
}
Submission Info

 

D - Menagerie

Time Limit: 2 sec / Memory Limit: 256 MB

Score : 500500 points

Problem Statement

Snuke, who loves animals, built a zoo.

There are NN animals in this zoo. They are conveniently numbered 11 through NN, and arranged in a circle. The animal numbered i(2≤i≤N−1)i(2≤i≤N−1) is adjacent to the animals numbered i−1i−1 and i+1i+1. Also, the animal numbered 11 is adjacent to the animals numbered 22 and NN, and the animal numbered NN is adjacent to the animals numbered N−1N−1 and 11.

There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies.

Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered ii answered sisi. Here, if sisi is ​​o​​​, the animal said that the two neighboring animals are of the same species, and if sisi is ​​x​​, the animal said that the two neighboring animals are of different species.

More formally, a sheep answered ​​o​​​ if the two neighboring animals are both sheep or both wolves, and answered ​​x​​​ otherwise. Similarly, a wolf answered ​​x​​​ if the two neighboring animals are both sheep or both wolves, and answered ​​o​​ otherwise.

Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print ​​-1​​.

Constraints

  • 3≤N≤1053≤N≤105
  • ss is a string of length NN consisting of ​​o​​​ and ​​x​​.

Input

The input is given from Standard Input in the following format:


NN ss


Output

If there does not exist an valid assignment that is consistent with ss, print ​​-1​​. Otherwise, print an string tt in the following format. The output is considered correct if the assignment described by tt is consistent with ss.

  • tt is a string of length NN consisting of ​​S​​​ and ​​W​​.
  • If titi is ​​S​​​, it indicates that the animal numbered ii is a sheep. If titi is ​​W​​, it indicates that the animal numbered ii is a wolf.

Sample Input 1 Copy

Copy


6 ooxoox


Sample Output 1 Copy

Copy


SSSWWS


For example, if the animals numbered 11, 22, 33, 44, 55 and 66 are respectively a sheep, sheep, sheep, wolf, wolf, and sheep, it is consistent with their responses. Besides, there is another valid assignment of species: a wolf, sheep, wolf, sheep, wolf and wolf.

Let us remind you: if the neiboring animals are of the same species, a sheep answers ​​o​​​ and a wolf answers ​​x​​​. If the neiboring animals are of different species, a sheep answers ​​x​​​ and a wolf answers ​​o​​.

AtCoder Regular Contest 069_i++_02

Sample Input 2 Copy

Copy


3 oox


Sample Output 2 Copy

Copy


-1


Print ​​-1​​ if there is no valid assignment of species.

Sample Input 3 Copy

Copy


10 oxooxoxoox


Sample Output 3 Copy

Copy


SSWWSSSWW


题意:

n个动物,一种为羊,一种为狼,排成一圈,

如果是该位置是羊,他说o表示,两边动物是同一种,x表示两边动物不是同一种。

如果是该位置是狼,他说o表示,两边动物不是同一种,x表示两边动物是同一种。

分析:

只要前两个位置确定就可以推出全部。

#include <bits/stdc++.h>
using namespace std;
#define INF 0x7fffffff
#define PI acos(-1.0)
#define MOD 2520
#define E 1e-12
using namespace std;
typedef long long ll;
const int MAXN=500000+5;//最大元素个数
char ans[MAXN];
string s;
int n;
int solve(char ch1,char ch2)
{
ans[0]=ch1;
ans[1]=ch2;
for(int i=1;i<n;i++)
{
if(s[i]=='o')
{
if(ans[i]=='S')
ans[i+1]=ans[i-1];
else
{
if(ans[i-1]=='W')
ans[i+1]='S';
else
ans[i+1]='W';
}
}
else if(s[i]=='x')
{
if(ans[i]=='W')
ans[i+1]=ans[i-1];
else
{
if(ans[i-1]=='W')
ans[i+1]='S';
else
ans[i+1]='W';
}
}
}
char temp;
if(s[0]=='o')
{
if(ans[0]=='S')
temp=ans[1];
else
{
if(ans[1]=='W')
temp='S';
else
temp='W';
}
}
else
{
if(ans[0]=='W')
temp=ans[1];
else
{
if(ans[1]=='W')
temp='S';
else
temp='W';
}
}
if(ans[n]==ans[0]&&temp==ans[n-1]) return 1;
else return 0;

}
int main()
{

scanf("%d",&n);

cin>>s;
if(solve('S','S')==1)
{

for(int i=0;i<n;i++)
cout<<ans[i];
//cout<<ans<<endl;
}
else if(solve('S','W')==1)
{
for(int i=0;i<n;i++)
cout<<ans[i];
//cout<<ans<<endl;
}
else if(solve('W','S')==1)
{
for(int i=0;i<n;i++)
cout<<ans[i];
//cout<<ans<<endl;
}
else if(solve('W','W')==1)
{
for(int i=0;i<n;i++)
cout<<ans[i];
//cout<<ans<<endl;
}
else
{
cout<<-1<<endl;
}
return 0;
}

 

举报

相关推荐

0 条评论