Just choose the two smaller ones.
answerA.py
a,b,c=map(int,input().split())
x=[a,b,c]
print(sum(x)-max(x))
Just erase the end in order and think about it.
answerB.py
s=input()
l=len(s)
for i in range(1,l//2):
k=(l-i*2)
if s[:k//2]==s[k//2:k]:
print(k)
break
Considering the ** actual push **, you can see that the odd-numbered and even-numbered pushes have different arrangements (see sample), so if you implement the arrangement obediently, it will be as follows. .. (It is also necessary to note that there are cases due to the evenness of n.)
answerC.py
n=int(input())
a=[i for i in input().split()]
b=[]
c=[]
if n%2==0:
for i in range(n):
if i%2==0:
b.append(a[i])
else:
c.append(a[i])
else:
for i in range(n):
if i%2==0:
c.append(a[i])
else:
b.append(a[i])
c=c[::-1]
print(" ".join(c)+" "+" ".join(b))
The policy was set normally, but the implementation could not be completed. (** Mounting power ** is one of the issues, but it seems that we have to handle the amount ...) It was discovered a few hours later that I was unaware of the basic mistakes in the basics.
As you can see by referring to this article, it seems that there are multiple definitions for the remainder, and each language behaves differently. It seems. To avoid this, you can change the negative number to a positive number as written in the code. (I think it's basic, but I didn't know about C ++ because I didn't know much about it. I should study C ++ more properly ...)
As for the policy, if you count the subsequence of length k from the whole including duplication, it will be $ _ {n + 1} C _k $, so ** Experiment considering whether there may be duplication ** To do. According to the experiment, let x be the number that exists in two, and when x is in the index i, j (0 <= i, j <= N), when both of them are included in the subsequence, they may overlap. If it doesn't exist and neither of the two is included in the subsequence, you can see that there is no duplication as well. Now consider ** when you want to include only one x in a subsequence **. Considering when the number of parts i + 1 to j-1 is included, the number is located on the right side for x in i and the number is located on the left side for x in j, so the different part You can see that it is divided as a column. Therefore, the numbers in ** 0 ~ i-1, j + 1 ~ N and the subsequence selected from either x are duplicated **, and $ _ {i + (nj)} C _ {k -1} $ is the number of overlapping subsequences for subsequences of length k. Therefore, you can find $ _ {n + 1} C k- {i + (nj)} C _ {k-1} $, but as I wrote earlier, do not generate a negative remainder. In the case of a negative number, you can reduce it to a positive remainder by adding MODs.
In addition, the calculation of the combination is borrowed from Mr. Kencho. For details, please refer to this article.
answerD.cc
#include<iostream>
#include<vector>
#include<utility>
using namespace std;
const int MAX = 1000000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
//Pretreatment to make a table
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++){
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
//Binomial coefficient calculation
long long COM(int n, int k){
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
//Preprocessing
COMinit();
int n;cin >> n;
vector<int> a(n+1);for(int i=0;i<n+1;i++){cin >> a[i];a[i]-=1;}
vector<bool> b(n,true);
for(int i=0;i<n+1;i++){b[a[i]]=!b[a[i]];}
pair<int,int> p=make_pair(-1,-1);
for(int i=0;i<n+1;i++){
if(b[a[i]]){
if(p.first==-1){p.first=i;}
else{p.second=i;break;}
}
}
//At first, c was output in the following part, but c<Since there is a possibility of 0, there is not exactly the remainder of the MOD
for(int i=1;i<=n+1;i++){
int c=COM(n+1,i)-COM(p.first+(n-p.second),i-1);
while(c<0){
c+=MOD;
}
cout << c%MOD << endl;
}
}
Recommended Posts