Codeforces Round #447 (Div. 2)

chinese Round瑟瑟发抖。神奇的OIer

A. QAQ
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.

Now Diamond has given Bort a string consisting of only uppercase English letters of length n. There is a great number of "QAQ" in the string (Diamond is so cute!).

Bort wants to know how many subsequences "QAQ" are in the string Diamond has given. Note that the letters "QAQ" don't have to be consecutive, but the order of letters should be exact.

Input

The only line contains a string of length n (1 ≤ n ≤ 100). It's guaranteed that the string only contains uppercase English letters.

Output

Print a single integer — the number of subsequences "QAQ" in the string.

Examples
input
QAQAQYSYIOIWIN
output
4
input
QAQQQZZYNOIWIN
output
3
Note

In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN".

 

 直接n^3的枚举啊,就是直接枚举QAQ,我还在想用PAT那种做法把它O(n),其实也是可以的么,看下左边几个右边几个

如果可以浪费空间的话就直接前缀和维护下啊

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    long long ans=0;
    for(int i=0;s[i];i++)
    {
        if(s[i]=='A')
        {
        int L=0,R=0;
           for(int j=i-1;j>=0;j--)
               if(s[j]=='Q') L++;
           for(int j=i+1;s[j];j++)
            if(s[j]=='Q') R++;
           ans+=L*R;
        }
    }
    cout<<ans;
    return 0;
}
B. Ralph And His Magic Field
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't always work properly. It works only if the product of integers in each row and each column equals to k, where k is either 1 or -1.

Now Ralph wants you to figure out the number of ways to put numbers in each block in such a way that the magic field works properly. Two ways are considered different if and only if there exists at least one block where the numbers in the first way and in the second way are different. You are asked to output the answer modulo 1000000007 = 109 + 7.

Note that there is no range of the numbers to put in the blocks, but we can prove that the answer is not infinity.

Input

The only line contains three integers nm and k (1 ≤ n, m ≤ 1018, k is either 1 or -1).

Output

Print a single number denoting the answer modulo 1000000007.

Examples
input
1 1 -1
output
1
input
1 3 1
output
1
input
3 3 -1
output
16
Note

In the first example the only way is to put -1 into the only block.

In the second example the only way is to put 1 into every block.

 

 这个题目就是让你填一个n行m列的方格,是的啊,我把最外面消去,里面是随便填的啊,只有1和-1,所以答案就是2^((m-1)*(n-1)),这个不能填就是-1是偶数的不能凑,也就是不能不同奇偶

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MD=1e9+7;
ll po(ll a,ll x)
{
   if(!x)return 1;
   ll t=po(a,x/2);
   t=t*t%MD;
   if(!(x&1))return t;
   return t*a%MD;
}
int main()
{
    ll n,m,k;
    cin>>n>>m>>k;
    if(k<0&&((n+m)&1))
        cout<<0;
    else
        cout<<po(po(2,n-1),m-1);
    return 0;
}
C. Marco and GCD Sequence
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time.

When he woke up, he only remembered that the key was a sequence of positive integers of some length n, but forgot the exact sequence. Let the elements of the sequence be a1, a2, ..., an. He remembered that he calculated gcd(ai, ai + 1, ..., aj) for every 1 ≤ i ≤ j ≤ n and put it into a set Sgcd here means the greatest common divisor.

Note that even if a number is put into the set S twice or more, it only appears once in the set.

Now Marco gives you the set S and asks you to help him figure out the initial sequence. If there are many solutions, print any of them. It is also possible that there are no sequences that produce the set S, in this case print -1.

Input

The first line contains a single integer m (1 ≤ m ≤ 1000) — the size of the set S.

The second line contains m integers s1, s2, ..., sm (1 ≤ si ≤ 106) — the elements of the set S. It's guaranteed that the elements of the set are given in strictly increasing order, that means s1 < s2 < ... < sm.

Output

If there is no solution, print a single line containing -1.

Otherwise, in the first line print a single integer n denoting the length of the sequence, n should not exceed 4000.

In the second line print n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the sequence.

We can show that if a solution exists, then there is a solution with n not exceeding 4000 and ai not exceeding 106.

If there are multiple solutions, print any of them.

Examples
input
4
2 4 6 12
output
3
4 6 12
input
2
2 3
output
-1
Note

In the first example 2 = gcd(4, 6), the other elements from the set appear in the sequence, and we can show that there are no values different from 2, 4, 6 and 12 among gcd(ai, ai + 1, ..., aj) for every 1 ≤ i ≤ j ≤ n.

其实-1就是所有数不能被最小的数整呗。所以好难啊

怎么去构造啊

这个往两个数之间插小的值是真的服,不好想到啊

#include<bits/stdc++.h>
using namespace std;
const int N=50050;
int a[N],n,mi=1<<30;
int main()
{
    int n,i;
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        if(a[i]<mi)mi=a[i];
    }
    for(i=1; i<=n; i++)
        if(a[i]%mi)break;
    if(i<=n)
        printf("-1");
    else
    {
        printf("%d\n%d",2*n-1,a[1]);
        for(i=2; i<=n; i++)
            printf(" %d %d",mi,a[i]);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/BobHuang/p/7864888.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值