【AtCoder】ARC058
ARC058
C - こだわり者いろはちゃん / Iroha's Obsession
暴力一个个枚举是最简单的方式
#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('\n')
#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,K;
bool vis[11];
bool check(int x) {
while(x) {
if(vis[x % 10]) return false;
x /= 10;
}
return true;
}
void Solve() {
read(N);read(K);
int d;
for(int i = 1 ; i <= K ; ++i) {
read(d);vis[d] = 1;
}
for(int i = N ; ; ++i) {
if(check(i)) {out(i);enter;return;}
}
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
D - いろはちゃんとマス目 / Iroha and a Grid
从\(A+1,B+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('\n')
#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);
}
const int MOD = 1000000007;
int H,W,A,B;
int fac[1000005],invfac[1000005];
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;
}
int fpow(int x,int c) {
int res = 1,t = x;
while(c) {
if(c & 1) res = mul(res,t);
t = mul(t,t);
c >>= 1;
}
return res;
}
int C(int n,int m) {
return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
void update(int &x,int y) {
x = inc(x,y);
}
int Way(int x1,int y1,int x2,int y2) {
return C(abs(y2 - y1) + abs(x2 - x1),abs(x2 - x1));
}
void Solve() {
read(H);read(W);read(A);read(B);
fac[0] = 1;
for(int i = 1 ; i <= 1000000 ; ++i) fac[i] = mul(fac[i - 1],i);
invfac[1000000] = fpow(fac[1000000],MOD - 2);
for(int i = 999999 ; i >= 0 ; --i) invfac[i] = mul(invfac[i + 1],i + 1);
int ans = 0;
while(1) {
++A;++B;
if(A > H || B > W) break;
update(ans,mul(Way(H,1,A,B),Way(A,B,1,W)));
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
E - 和風いろはちゃん / Iroha and Haiku
把合法的一段序列拿出来,搜一下发现个数不超过17000个,建成AC自动机节点数不超过40000个,直接AC自动机上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('\n')
#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);
}
const int MOD = 1000000007;
int N,X,Y,Z;
int nxt[200005][12],Ncnt,pre[200005],dp[2][40000][2];
bool ed[200005];
vector<vector<int> > line[3],all;
vector<int> t;
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 getline(int id,int x) {
if(!x) {
line[id].pb(t);
return;
}
for(int i = 1 ; i <= x ; ++i) {
t.pb(i);
getline(id,x - i);
t.pop_back();
}
}
void Append(int id,vector<int> b = {}) {
if(id >= 3) {
all.pb(b);
return;
}
for(auto a : line[id]) {
vector<int> c = b;
c.insert(c.end(),a.begin(),a.end());
Append(id + 1,c);
}
}
void Insert(vector<int> s) {
int p = 1;
for(auto t : s) {
if(!nxt[p][t]) {
nxt[p][t] = ++Ncnt;
}
p = nxt[p][t];
}
ed[p] = 1;
}
queue<int> Q;
void build_ACAM() {
for(int i = 1 ; i <= 10 ; ++i) nxt[0][i] = 1;
pre[1] = 0;
Q.push(1);
while(!Q.empty()) {
int u = Q.front();Q.pop();
for(int i = 1 ; i <= 10 ; ++i) {
if(nxt[u][i]) {
Q.push(nxt[u][i]);
pre[nxt[u][i]] = nxt[pre[u]][i];
}
else nxt[u][i] = nxt[pre[u]][i];
}
}
}
void Solve() {
read(N);read(X);read(Y);read(Z);
getline(0,X);getline(1,Y);getline(2,Z);
Append(0);
Ncnt = 1;
for(auto k : all) {
Insert(k);
}
build_ACAM();
int cur = 0;dp[0][1][0] = 1;
for(int i = 1 ; i <= N ; ++i) {
memset(dp[cur ^ 1],0,sizeof(dp[cur ^ 1]));
for(int u = 1 ; u <= Ncnt ; ++u) {
for(int k = 0 ; k <= 1 ; ++k) {
for(int h = 1 ; h <= 10 ; ++h) {
update(dp[cur ^ 1][nxt[u][h]][k | ed[nxt[u][h]]],dp[cur][u][k]);
}
}
}
cur ^= 1;
}
int ans = 0;
for(int u = 1 ; u <= Ncnt ; ++u) {
update(ans,dp[cur][u][1]);
}
out(ans);enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
return 0;
}
F - 文字列大好きいろはちゃん / Iroha Loves Strings
nmd,为什么,和别人写的一样我就是过不去
用随机卡过的,放弃治疗了
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#define enter putchar('\n')
#define space putchar(' ')
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define eps 1e-7
#define MAXN 1000005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
res = 0;char c = getchar();T f = 1;
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) {putchar('-');x = -x;}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
int N,K,L[2005];
char s[2005][10005];
bool vis[2005][10005];
int dp[10005],tot;
pii que[8005],tmp[8005];
char ans[10005];
void Init() {
read(N);read(K);
for(int i = 1 ; i <= N ; ++i) {
scanf("%s",s[i] + 1);
L[i] = strlen(s[i] + 1);
}
vis[N + 1][0] = 1;
for(int i = N ; i >= 1 ; --i) {
for(int j = K ; j >= 0 ; --j) {
vis[i][j] |= vis[i + 1][j];
if(j >= L[i]) vis[i][j] |= vis[i + 1][j - L[i]];
}
}
for(int i = 1 ; i <= K ; ++i) dp[i] = N + 1;
}
void Solve() {
for(int i = 1 ; i <= K ; ++i) {
int t = 26;
for(int j = dp[i - 1] + 1 ; j <= N ; ++j) {
if(K - L[j] - i + 1 >= 0 && vis[j + 1][K - L[j] - i + 1]) {
t = min(t,s[j][1] - 'a');
}
}
for(int j = 1 ; j <= tot ; ++j) {
t = min(t,s[que[j].fi][que[j].se + 1] - 'a');
}
ans[i] = 'a' + t;
int tp = 0;
for(int j = dp[i - 1] + 1 ; j <= N ; ++j) {
if(K - L[j] - i + 1 >= 0 && vis[j + 1][K - L[j] - i + 1]) {
if(s[j][1] - 'a' == t) {
if(L[j] == 1) dp[i] = min(dp[i],j);
else tmp[++tp] = mp(j,1);
}
}
}
for(int j = 1 ; j <= tot ; ++j) {
if(s[que[j].fi][que[j].se + 1] - 'a' == t) {
if(que[j].se + 1 == L[que[j].fi]) dp[i] = min(dp[i],que[j].fi);
else tmp[++tp] = mp(que[j].fi,que[j].se + 1);
}
}
random_shuffle(tmp + 1,tmp + tp + 1);
tot = min(tp,3 * N);
for(int j = 1 ; j <= tot ; ++j) que[j] = tmp[j];
}
for(int i = 1 ; i <= K ; ++i) {
putchar(ans[i]);
}
enter;
}
int main() {
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Init();
Solve();
}