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

  • 4≤N≤105
  • 1≤Ai≤109
  • 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 <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <map>
    #include <set>
    using namespace std;
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>y?x:y)
    #define min(x,y) (x<y?x:y)
    #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;
        }
    };
    multiset<ll,cmp>s;
    multiset<ll>::iterator it;
    priority_queue<ll,vector<ll> >q;
    ll cnt,x,n;
    int main()
    {
        while(scanf("%lld",&n)!=EOF)
        {
            s.clear();
            for(int i=0;i<n;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 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

  • 1≤N≤52
  • |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 <iostream>
    #include <algorithm>
    #include <cstring>
    #include <cstdio>
    #include <vector>
    #include <queue>
    #include <cstdlib>
    #include <iomanip>
    #include <cmath>
    #include <cassert>
    #include <ctime>
    #include <map>
    #include <set>
    using namespace std;
    #define lowbit(x) (x&(-x))
    #define max(x,y) (x>y?x:y)
    #define min(x,y) (x<y?x:y)
    #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;
    }
时间: 2024-07-30 03:34:00

Atcoder ABC 071 C,D的相关文章

AtCoder ABC 129F Takahashi&#39;s Basics in Education and Learning

题目链接:https://atcoder.jp/contests/abc129/tasks/abc129_f 题目大意 给定一个长度为 L ,首项为 A,公差为 B 的等差数列 S,将这 L 个数拼起来,记作 N,求 N % M. 分析 设 bit(i) 为第 i 项所需要进行的十进制位移. 则 $N = S_0 * 10^{bit(0)} + S_1 * 10^{bit(1)} + \dots + S_{L - 1} * 10^{bit(L - 1)}$. 一项一项地算是肯定要超时的,不过注意

Atcoder ABC 141

Atcoder ABC 141 A - Weather Prediction SB题啊,不讲. #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; char ch[50]; int main() { scanf("%s",ch+1); if(ch[1] == 'S') puts("Cloudy

题解 [Atcoder ABC 161] A,B,C

题解 [Atcoder ABC 161] A,B,C A: 水题,按题意模拟即可. code: #include<bits/stdc++.h> #define ft(i,l,r) for(register int i=l;i<=r;i++) #define fd(i,r,l) for(register int i=r;i>=l;i--) using namespace std; int a,b,c; int main() { cin>>a>>b>>

AtCoder ABC 127F Absolute Minima

题目链接:https://atcoder.jp/contests/abc127/tasks/abc127_f 题目大意 初始状态下$f(x) = 0$,现在有 2 种模式的询问,第一种以“1 a b”的形式,需要进行操作$f(x) = f(x) + |x - a| + b$:第二种以“2”的形式,求使得 f(x) 取得最小值的 x 取值和 f(x) 值,如果有多个 x,输出任意一个即可. 分析 考虑第一种询问已经出现了 k 次,现在遇到第二种询问.此时$f(x) = \sum_{i = 1}^k

AtCoder ABC 130F Minimum Bounding Box

题目链接:https://atcoder.jp/contests/abc130/tasks/abc130_f 题目大意 给定地图上 N 个点的坐标和移动方向,它们会以每秒 1 个单位的速度移动,设 Ans(t) 为在 t 时刻,$(x_{max} - x_{min}) * (y_{max} - y_{min})$的值,求 Ans(t) 的最小值.(最小值可能不是一个整数) 分析 稍加思考可以发现,不是所有点的所有坐标都对答案有影响,很多点完全可以忽略不计,下面以 Y 坐标为例,讨论影响$(y_{

AtCoder ABC 154E Almost Everywhere Zero

题目链接:https://atcoder.jp/contests/abc154/tasks/abc154_e 题目大意 给定一个整数N($1 \leq N \leq 10^{100}$)和K($1 \leq K \leq 3$),求[1, N]区间内数位上只有K个非零数的整数个数. 分析 找一下规律即可,详情见代码注释. 代码如下 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 /*-------------------Define

AtCoder ABC 155D Pairs

题目链接:https://atcoder.jp/contests/abc155/tasks/abc155_d 题目大意 给定$N$个整数$A_1, A_2, \dots, A_N$, 求集合$S = \{A_i * A_j | 1 \leq i, j \leq N 且 i \neq j\}$的第$K$小. 分析 首先,通过把$N$个数分为正数,负数,零,再排下序,我们可以计算$S$中所有的正数,负数以及零的数目,进而可以判断出第$K$小的数是正数,是负数,还是零. 如果第$K$小的数是零,无需多

AtCoder ABC 155F Perils in Parallel

题目链接:https://atcoder.jp/contests/abc155/tasks/abc155_f 题目大意 分析 代码如下 原文地址:https://www.cnblogs.com/zaq19970105/p/12340031.html

AtCoder ABC 157E Simple String Queries

题目链接:https://atcoder.jp/contests/abc157/tasks/abc157_e 题目大意 给定一串全由小写英文字母组成的字符串,然后顺序给出$Q$个操作,一种为替换字符串中的某个字符:另一种为查询字符串某个区间里面有多少个不同的字符.要求顺序输出第二种操作的结果. 分析 线段树单点更新,每个节点存一个32位整数,其中26位代表26个英文字母,更新的话只要节点求或就行了. 其他方法1:用26个树状数组,这个原理是一样的,但总感觉没有只用一棵线段树简明. 其他方法2:把