Atcoder ABC 071 C,D

C - Make a Rectangle


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

We have N sticks with negligible thickness. The length of the i-th stick is Ai.

Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides. Find the maximum possible area of the rectangle.

Constraints

  • 4N105
  • 1Ai109
  • Ai is an integer.

Input

Input is given from Standard Input in the following format:

N
A1 A2 ... AN

Output

Print the maximum possible area of the rectangle. If no rectangle can be formed, print 0.


Sample Input 1

6
3 1 2 4 2 1

Sample Output 1

2

1×2 rectangle can be formed.


Sample Input 2

4
1 2 3 4

Sample Output 2

0

No rectangle can be formed.


Sample Input 3

10
3 3 3 3 4 4 4 5 5 5

Sample Output 3

20
挑最长边即可,并且最长边最少的两条
    #include  
    #include  
    #include  
    #include 
    #include  
    #include  
    #include  
    #include 
    #include 
    #include 
    #include  
    #include  
    #include <set> 
    using namespace std; 
    #define lowbit(x) (x&(-x)) 
    #define max(x,y) (x>y?x:y) 
    #define min(x,y) (x#define MAX 100000000000000000 
    #define MOD 1000000007
    #define pi acos(-1.0) 
    #define ei exp(1) 
    #define PI 3.141592653589793238462
    #define ios() ios::sync_with_stdio(false)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    const int maxn=1e6+7;
    struct cmp
    {
        bool operator()(const ll &a,const ll &b)
        {
            return a>b;
        }
    };
    multisets;
    multiset::iterator it;
    priority_queue >q;
    ll cnt,x,n;
    int main()
    {
        while(scanf("%lld",&n)!=EOF)
        {
            s.clear();
            for(int i=0;i)
            {
                scanf("%lld",&x);
                s.insert(x);
            }
            x=0;
            for(it=s.begin();it!=s.end();it++)
            {
                if(*it==x) cnt++;
                else x=*it,cnt=1;
                if(cnt==2) q.push(x),cnt=0;
            }
            if(q.size()<2) printf("0\n");
            else x=q.top(),q.pop(),printf("%lld\n",x*q.top());
            while(!q.empty()) q.pop();
        }
        return 0;
    }

D - Coloring Dominoes


Time limit : 2sec / Memory limit : 256MB

Score : 400 points

Problem Statement

We have a board with a 2×N grid. Snuke covered the board with N dominoes without overlaps. Here, a domino can cover a 1×2 or 2×1 square.

Then, Snuke decided to paint these dominoes using three colors: red, cyan and green. Two dominoes that are adjacent by side should be painted by different colors. Here, it is not always necessary to use all three colors.

Find the number of such ways to paint the dominoes, modulo 1000000007.

The arrangement of the dominoes is given to you as two strings S1 and S2 in the following manner:

  • Each domino is represented by a different English letter (lowercase or uppercase).
  • The j-th character in Si represents the domino that occupies the square at the i-th row from the top and j-th column from the left.

Constraints

  • 1N52
  • |S1|=|S2|=N
  • S1 and S2 consist of lowercase and uppercase English letters.
  • S1 and S2 represent a valid arrangement of dominoes.

Input

Input is given from Standard Input in the following format:

N
S1
S2

Output

Print the number of such ways to paint the dominoes, modulo 1000000007.


Sample Input 1

Copy
3
aab
ccb

Sample Output 1

6

There are six ways as shown below:


Sample Input 2

1
Z
Z

Sample Output 2

3

Note that it is not always necessary to use all the colors.


Sample Input 3

52
RvvttdWIyyPPQFFZZssffEEkkaSSDKqcibbeYrhAljCCGGJppHHn
RLLwwdWIxxNNQUUXXVVMMooBBaggDKqcimmeYrhAljOOTTJuuzzn

Sample Output 3

958681902

每次都和之前方块的状态有关。
1.竖+竖:ans=ans*2;
2.竖+横:ans=ans*2;
3.横+竖:ans=ans*1;
4.横+横;ans=ans*3;(上1下2,则只可能:1.上2下1,2.上3下1,3.上2下3)
开始时:若为竖C(3,1),若为横:C(3,2).
    #include  
    #include  
    #include  
    #include 
    #include  
    #include  
    #include  
    #include 
    #include 
    #include 
    #include  
    #include  
    #include <set> 
    using namespace std; 
    #define lowbit(x) (x&(-x)) 
    #define max(x,y) (x>y?x:y) 
    #define min(x,y) (x#define MAX 100000000000000000 
    #define MOD 1000000007
    #define pi acos(-1.0) 
    #define ei exp(1) 
    #define PI 3.141592653589793238462
    #define ios() ios::sync_with_stdio(false)
    #define INF 1044266558
    #define mem(a) (memset(a,0,sizeof(a)))
    typedef long long ll;
    const int maxn=1e6+7;
    char a[55],b[55];
    int flag,i,n;
    ll ans;
    int main()
    {
        while(scanf("%d %s %s",&n,a,b)!=EOF)
        {
            ans=1,i=0;
            if(a[i]==b[i]) i++,ans=ans*3%MOD,flag=1;
            else i+=2,ans=ans*6%MOD,flag=0;
            while(i<n)
            {
                if(a[i]==b[i])
                {
                    if(flag) ans=ans*2%MOD,i++;
                    else flag^=1,i++;
                }
                else
                {
                    if(flag) ans=ans*2%MOD,flag^=1,i+=2;
                    else ans=ans*3%MOD,i+=2;
                }
            }
            printf("%lld\n",ans);
        }
        return 0;
    }

 

转载于:https://www.cnblogs.com/shinianhuanniyijuhaojiubujian/p/7404011.html

你可能感兴趣的:(Atcoder ABC 071 C,D)