为啥这场ARC那么水……一个点就切完了
ARC059
C - いっしょ / Be Together
枚举就行
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('
')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N;
int64 a[105];
void Solve() {
read(N);
for(int i = 1 ; i <= N ; ++i) read(a[i]);
int64 ans = 1e18;
for(int64 i = -100 ; i <= 100 ; ++i) {
int64 tmp = 0;
for(int j = 1 ; j <= N ; ++j) {
tmp += (a[j] - i) * (a[j] - i);
}
ans = min(ans,tmp);
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
D - アンバランス / Unbalanced
要么是两个相邻的字母相同,要么是两个相同的字母中间隔了一个
其余的情况都会至少包含这两种情况之一
所以只要判这两种就好了
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('
')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
char s[MAXN];
int N;
void Solve() {
scanf("%s",s + 1);
N = strlen(s + 1);
for(int i = 1 ; i < N ; ++i) {
if(s[i] == s[i + 1]) {out(i);space;out(i + 1);enter;return;}
if(i != N - 1) {
if(s[i] == s[i + 2]) {out(i);space;out(i + 2);enter;return;}
}
}
out(-1);space;out(-1);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
E - キャンディーとN人の子供 / Children and Candies
每个值其实可以分开考虑
设(dp[i][j])为前i个数指数的总和为j的和,枚举下一个数的指数,计算从([A_{i + 1},B_{i + 1}])的所有情况,更新即可
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('
')
#define eps 1e-10
#define MAXN 405
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N;
int C,A[MAXN],B[MAXN];
int num[MAXN][MAXN],sum[MAXN][MAXN];
int dp[2][MAXN];
int inc(int a,int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
void update(int &x,int y) {
x = inc(x,y);
}
void Solve() {
read(N);read(C);
for(int i = 1 ; i <= N ; ++i) read(A[i]);
for(int i = 1 ; i <= N ; ++i) read(B[i]);
for(int i = 1 ; i <= 400 ; ++i) {
num[i][0] = 1;
for(int j = 1 ; j <= 400 ; ++j) {
num[i][j] = mul(num[i][j - 1],i);
}
}
for(int j = 0 ; j <= 400 ; ++j) {
for(int i = 1 ; i <= 400 ; ++i) {
sum[i][j] = inc(sum[i - 1][j],num[i][j]);
}
}
int cur = 0;dp[cur][0] = 1;
for(int i = 1 ; i <= N ; ++i) {
memset(dp[cur ^ 1],0,sizeof(dp[cur ^ 1]));
for(int j = 0 ; j <= C ; ++j) {
for(int h = 0 ; h <= C - j ; ++h) {
update(dp[cur ^ 1][j + h],mul(dp[cur][j],inc(sum[B[i]][h],MOD - sum[A[i] - 1][h])));
}
}
cur ^= 1;
}
out(dp[cur][C]);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
F - バイナリハック / Unhappy Hacking
这个题就是,我如果新加一个值,默认和我需要的下一位相同,而我摁下一个B后,当前最后一位的值就不必要是和s中对应位置相同了,于是方案数乘2
设(dp[i][j])为第i次操作,字符串长度为j,这样dp即可
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('
')
#define eps 1e-10
#define MAXN 5005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
const int MOD = 1000000007;
int inc(int a,int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
return 1LL * a * b % MOD;
}
void update(int &x,int y) {
x = inc(x,y);
}
char s[5005];
int dp[5005][5005],N,L;
void Solve() {
read(N);
scanf("%s",s + 1);
L = strlen(s + 1);
dp[0][0] = 1;
for(int i = 0 ; i < N ; ++i) {
for(int j = 0 ; j <= N ; ++j) {
if(j == 0) update(dp[i + 1][j],dp[i][j]);
else update(dp[i + 1][j - 1],mul(dp[i][j],2));
update(dp[i + 1][j + 1],dp[i][j]);
}
}
out(dp[N][L]);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}