【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();
}
【AtCoder】ARC058的更多相关文章
- 【AtCoder】ARC092 D - Two Sequences
[题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...
- 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring
[题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...
- 【AtCoder】ARC 081 E - Don't Be a Subsequence
[题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...
- 【AtCoder】AGC022 F - Leftmost Ball 计数DP
[题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...
- 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT
[题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...
- 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分
[题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...
- 【AtCoder】ARC095 E - Symmetric Grid 模拟
[题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...
- 【Atcoder】AGC022 C - Remainder Game 搜索
[题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...
- 【Atcoder】AGC 020 B - Ice Rink Game 递推
[题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...
随机推荐
- Django-常用异常
1 from rest_framework.authentication import BasicAuthentication raise AuthenticationFailed(res.dict) ...
- ansible-cmdb 解析(ansible all -m setup )收集过来的信息并以html方式显示。
首先安装 ansible-cmdb 直接pip install ansible-cmdb 安装 然后执行收集信息命令 ansible all -m setup >/tmp/out/ 修改下ans ...
- Django基础之ModelForm
1. form与model的终极结合 class BookForm(forms.ModelForm): class Meta: model = models.Book fields = "_ ...
- easyUI的c if
{field:'domdistrict2',title:'区县',width:100}, {field:'option',title:'操作',width:fixWidth(0.08),align:' ...
- 异步机制 - Overlapped
1 前面说到 GetOverlappedResult的bWait含义 GetOverlappedResult的bWait含义表示是否需要等待,如果IO还处于PENDING状态,内部大概实现是这样 hO ...
- IdentityServer4入门一
这几天学习IdentityServer4,感觉内容有点乱,也可能自己水平有限吧.但为了巩固学习的内容,也打算自己理一下思路. 首先IdentityServer解决什么问题? 下图是我们的一个程序的组织 ...
- 安装 PostgreSQL 时丢失 libintl-8.dll 解决方案
发表于 2013 年 11 月 13 日 修订于 2018 年 05 月 05 日 PostgreSQL 比 MySQL 有更多的高级特性,而且微信支付的数据库也是基于 PostgreSQL ...
- What do you do as a DevOps?
https://ilhicas.com/2019/08/11/What-you-as-a-Devops.html Introduction In this post I'll just explain ...
- CSS — 隐藏滚动条,依旧可以滚动
公司的系统,在PC端可以管理我们的公众号,在发布模块页面时有一个预览功能,呈现页面在手机端的样式. 做法很简单,一会就完成了,但是在预览内容过长时手机外框会有一个滚动条,影响美观,于是就想把它去掉,有 ...
- laydate V5-0-8动态设置min值
laydate通过设置min,max值来对用户输入的时间做约束 laydate v1.0版本 //日期插件 var start={ elem:"#start", format:&q ...