ARC058

C - こだわり者いろはちゃん / Iroha's Obsession

暴力一个个枚举是最简单的方式

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define mp make_pair
  6. #define pb push_back
  7. #define space putchar(' ')
  8. #define enter putchar('\n')
  9. #define eps 1e-10
  10. #define MAXN 100005
  11. //#define ivorysi
  12. using namespace std;
  13. typedef long long int64;
  14. typedef unsigned int u32;
  15. typedef double db;
  16. template<class T>
  17. void read(T &res) {
  18. res = 0;T f = 1;char c = getchar();
  19. while(c < '0' || c > '9') {
  20. if(c == '-') f = -1;
  21. c = getchar();
  22. }
  23. while(c >= '0' && c <= '9') {
  24. res = res * 10 +c - '0';
  25. c = getchar();
  26. }
  27. res *= f;
  28. }
  29. template<class T>
  30. void out(T x) {
  31. if(x < 0) {x = -x;putchar('-');}
  32. if(x >= 10) {
  33. out(x / 10);
  34. }
  35. putchar('0' + x % 10);
  36. }
  37. int N,K;
  38. bool vis[11];
  39. bool check(int x) {
  40. while(x) {
  41. if(vis[x % 10]) return false;
  42. x /= 10;
  43. }
  44. return true;
  45. }
  46. void Solve() {
  47. read(N);read(K);
  48. int d;
  49. for(int i = 1 ; i <= K ; ++i) {
  50. read(d);vis[d] = 1;
  51. }
  52. for(int i = N ; ; ++i) {
  53. if(check(i)) {out(i);enter;return;}
  54. }
  55. }
  56. int main() {
  57. #ifdef ivorysi
  58. freopen("f1.in","r",stdin);
  59. #endif
  60. Solve();
  61. return 0;
  62. }

D - いろはちゃんとマス目 / Iroha and a Grid

从\(A+1,B+1\)开始斜向上的对角线上的点必须经过,计算经过这些点的路径条数和

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define mp make_pair
  6. #define pb push_back
  7. #define space putchar(' ')
  8. #define enter putchar('\n')
  9. #define eps 1e-10
  10. #define MAXN 100005
  11. //#define ivorysi
  12. using namespace std;
  13. typedef long long int64;
  14. typedef unsigned int u32;
  15. typedef double db;
  16. template<class T>
  17. void read(T &res) {
  18. res = 0;T f = 1;char c = getchar();
  19. while(c < '0' || c > '9') {
  20. if(c == '-') f = -1;
  21. c = getchar();
  22. }
  23. while(c >= '0' && c <= '9') {
  24. res = res * 10 +c - '0';
  25. c = getchar();
  26. }
  27. res *= f;
  28. }
  29. template<class T>
  30. void out(T x) {
  31. if(x < 0) {x = -x;putchar('-');}
  32. if(x >= 10) {
  33. out(x / 10);
  34. }
  35. putchar('0' + x % 10);
  36. }
  37. const int MOD = 1000000007;
  38. int H,W,A,B;
  39. int fac[1000005],invfac[1000005];
  40. int inc(int a,int b) {
  41. return a + b >= MOD ? a + b - MOD : a + b;
  42. }
  43. int mul(int a,int b) {
  44. return 1LL * a * b % MOD;
  45. }
  46. int fpow(int x,int c) {
  47. int res = 1,t = x;
  48. while(c) {
  49. if(c & 1) res = mul(res,t);
  50. t = mul(t,t);
  51. c >>= 1;
  52. }
  53. return res;
  54. }
  55. int C(int n,int m) {
  56. return mul(fac[n],mul(invfac[m],invfac[n - m]));
  57. }
  58. void update(int &x,int y) {
  59. x = inc(x,y);
  60. }
  61. int Way(int x1,int y1,int x2,int y2) {
  62. return C(abs(y2 - y1) + abs(x2 - x1),abs(x2 - x1));
  63. }
  64. void Solve() {
  65. read(H);read(W);read(A);read(B);
  66. fac[0] = 1;
  67. for(int i = 1 ; i <= 1000000 ; ++i) fac[i] = mul(fac[i - 1],i);
  68. invfac[1000000] = fpow(fac[1000000],MOD - 2);
  69. for(int i = 999999 ; i >= 0 ; --i) invfac[i] = mul(invfac[i + 1],i + 1);
  70. int ans = 0;
  71. while(1) {
  72. ++A;++B;
  73. if(A > H || B > W) break;
  74. update(ans,mul(Way(H,1,A,B),Way(A,B,1,W)));
  75. }
  76. out(ans);enter;
  77. }
  78. int main() {
  79. #ifdef ivorysi
  80. freopen("f1.in","r",stdin);
  81. #endif
  82. Solve();
  83. return 0;
  84. }

E - 和風いろはちゃん / Iroha and Haiku

把合法的一段序列拿出来,搜一下发现个数不超过17000个,建成AC自动机节点数不超过40000个,直接AC自动机上dp即可

  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pii pair<int,int>
  5. #define mp make_pair
  6. #define pb push_back
  7. #define space putchar(' ')
  8. #define enter putchar('\n')
  9. #define eps 1e-10
  10. #define MAXN 100005
  11. //#define ivorysi
  12. using namespace std;
  13. typedef long long int64;
  14. typedef unsigned int u32;
  15. typedef double db;
  16. template<class T>
  17. void read(T &res) {
  18. res = 0;T f = 1;char c = getchar();
  19. while(c < '0' || c > '9') {
  20. if(c == '-') f = -1;
  21. c = getchar();
  22. }
  23. while(c >= '0' && c <= '9') {
  24. res = res * 10 +c - '0';
  25. c = getchar();
  26. }
  27. res *= f;
  28. }
  29. template<class T>
  30. void out(T x) {
  31. if(x < 0) {x = -x;putchar('-');}
  32. if(x >= 10) {
  33. out(x / 10);
  34. }
  35. putchar('0' + x % 10);
  36. }
  37. const int MOD = 1000000007;
  38. int N,X,Y,Z;
  39. int nxt[200005][12],Ncnt,pre[200005],dp[2][40000][2];
  40. bool ed[200005];
  41. vector<vector<int> > line[3],all;
  42. vector<int> t;
  43. int inc(int a,int b) {
  44. return a + b >= MOD ? a + b - MOD : a + b;
  45. }
  46. int mul(int a,int b) {
  47. return 1LL * a * b % MOD;
  48. }
  49. void update(int &x,int y) {
  50. x = inc(x,y);
  51. }
  52. void getline(int id,int x) {
  53. if(!x) {
  54. line[id].pb(t);
  55. return;
  56. }
  57. for(int i = 1 ; i <= x ; ++i) {
  58. t.pb(i);
  59. getline(id,x - i);
  60. t.pop_back();
  61. }
  62. }
  63. void Append(int id,vector<int> b = {}) {
  64. if(id >= 3) {
  65. all.pb(b);
  66. return;
  67. }
  68. for(auto a : line[id]) {
  69. vector<int> c = b;
  70. c.insert(c.end(),a.begin(),a.end());
  71. Append(id + 1,c);
  72. }
  73. }
  74. void Insert(vector<int> s) {
  75. int p = 1;
  76. for(auto t : s) {
  77. if(!nxt[p][t]) {
  78. nxt[p][t] = ++Ncnt;
  79. }
  80. p = nxt[p][t];
  81. }
  82. ed[p] = 1;
  83. }
  84. queue<int> Q;
  85. void build_ACAM() {
  86. for(int i = 1 ; i <= 10 ; ++i) nxt[0][i] = 1;
  87. pre[1] = 0;
  88. Q.push(1);
  89. while(!Q.empty()) {
  90. int u = Q.front();Q.pop();
  91. for(int i = 1 ; i <= 10 ; ++i) {
  92. if(nxt[u][i]) {
  93. Q.push(nxt[u][i]);
  94. pre[nxt[u][i]] = nxt[pre[u]][i];
  95. }
  96. else nxt[u][i] = nxt[pre[u]][i];
  97. }
  98. }
  99. }
  100. void Solve() {
  101. read(N);read(X);read(Y);read(Z);
  102. getline(0,X);getline(1,Y);getline(2,Z);
  103. Append(0);
  104. Ncnt = 1;
  105. for(auto k : all) {
  106. Insert(k);
  107. }
  108. build_ACAM();
  109. int cur = 0;dp[0][1][0] = 1;
  110. for(int i = 1 ; i <= N ; ++i) {
  111. memset(dp[cur ^ 1],0,sizeof(dp[cur ^ 1]));
  112. for(int u = 1 ; u <= Ncnt ; ++u) {
  113. for(int k = 0 ; k <= 1 ; ++k) {
  114. for(int h = 1 ; h <= 10 ; ++h) {
  115. update(dp[cur ^ 1][nxt[u][h]][k | ed[nxt[u][h]]],dp[cur][u][k]);
  116. }
  117. }
  118. }
  119. cur ^= 1;
  120. }
  121. int ans = 0;
  122. for(int u = 1 ; u <= Ncnt ; ++u) {
  123. update(ans,dp[cur][u][1]);
  124. }
  125. out(ans);enter;
  126. }
  127. int main() {
  128. #ifdef ivorysi
  129. freopen("f1.in","r",stdin);
  130. #endif
  131. Solve();
  132. return 0;
  133. }

F - 文字列大好きいろはちゃん / Iroha Loves Strings

nmd,为什么,和别人写的一样我就是过不去

用随机卡过的,放弃治疗了

  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cstdio>
  4. #include <cstring>
  5. #include <queue>
  6. #include <cmath>
  7. #define enter putchar('\n')
  8. #define space putchar(' ')
  9. #define mp make_pair
  10. #define pb push_back
  11. #define fi first
  12. #define se second
  13. #define pii pair<int,int>
  14. #define eps 1e-7
  15. #define MAXN 1000005
  16. //#define ivorysi
  17. using namespace std;
  18. typedef long long int64;
  19. typedef double db;
  20. template<class T>
  21. void read(T &res) {
  22. res = 0;char c = getchar();T f = 1;
  23. while(c < '0' || c > '9') {
  24. if(c == '-') f = -1;
  25. c = getchar();
  26. }
  27. while(c >= '0' && c <= '9') {
  28. res = res * 10 + c - '0';
  29. c = getchar();
  30. }
  31. res *= f;
  32. }
  33. template<class T>
  34. void out(T x) {
  35. if(x < 0) {putchar('-');x = -x;}
  36. if(x >= 10) {
  37. out(x / 10);
  38. }
  39. putchar('0' + x % 10);
  40. }
  41. int N,K,L[2005];
  42. char s[2005][10005];
  43. bool vis[2005][10005];
  44. int dp[10005],tot;
  45. pii que[8005],tmp[8005];
  46. char ans[10005];
  47. void Init() {
  48. read(N);read(K);
  49. for(int i = 1 ; i <= N ; ++i) {
  50. scanf("%s",s[i] + 1);
  51. L[i] = strlen(s[i] + 1);
  52. }
  53. vis[N + 1][0] = 1;
  54. for(int i = N ; i >= 1 ; --i) {
  55. for(int j = K ; j >= 0 ; --j) {
  56. vis[i][j] |= vis[i + 1][j];
  57. if(j >= L[i]) vis[i][j] |= vis[i + 1][j - L[i]];
  58. }
  59. }
  60. for(int i = 1 ; i <= K ; ++i) dp[i] = N + 1;
  61. }
  62. void Solve() {
  63. for(int i = 1 ; i <= K ; ++i) {
  64. int t = 26;
  65. for(int j = dp[i - 1] + 1 ; j <= N ; ++j) {
  66. if(K - L[j] - i + 1 >= 0 && vis[j + 1][K - L[j] - i + 1]) {
  67. t = min(t,s[j][1] - 'a');
  68. }
  69. }
  70. for(int j = 1 ; j <= tot ; ++j) {
  71. t = min(t,s[que[j].fi][que[j].se + 1] - 'a');
  72. }
  73. ans[i] = 'a' + t;
  74. int tp = 0;
  75. for(int j = dp[i - 1] + 1 ; j <= N ; ++j) {
  76. if(K - L[j] - i + 1 >= 0 && vis[j + 1][K - L[j] - i + 1]) {
  77. if(s[j][1] - 'a' == t) {
  78. if(L[j] == 1) dp[i] = min(dp[i],j);
  79. else tmp[++tp] = mp(j,1);
  80. }
  81. }
  82. }
  83. for(int j = 1 ; j <= tot ; ++j) {
  84. if(s[que[j].fi][que[j].se + 1] - 'a' == t) {
  85. if(que[j].se + 1 == L[que[j].fi]) dp[i] = min(dp[i],que[j].fi);
  86. else tmp[++tp] = mp(que[j].fi,que[j].se + 1);
  87. }
  88. }
  89. random_shuffle(tmp + 1,tmp + tp + 1);
  90. tot = min(tp,3 * N);
  91. for(int j = 1 ; j <= tot ; ++j) que[j] = tmp[j];
  92. }
  93. for(int i = 1 ; i <= K ; ++i) {
  94. putchar(ans[i]);
  95. }
  96. enter;
  97. }
  98. int main() {
  99. #ifdef ivorysi
  100. freopen("f1.in","r",stdin);
  101. #endif
  102. Init();
  103. Solve();
  104. }

【AtCoder】ARC058的更多相关文章

  1. 【AtCoder】ARC092 D - Two Sequences

    [题目]AtCoder Regular Contest 092 D - Two Sequences [题意]给定n个数的数组A和数组B,求所有A[i]+B[j]的异或和(1<=i,j<=n ...

  2. 【Atcoder】CODE FESTIVAL 2017 qual A D - Four Coloring

    [题意]给定h,w,d,要求构造矩阵h*w满足任意两个曼哈顿距离为d的点都不同色,染四色. [算法]结论+矩阵变换 [题解] 曼哈顿距离是一个立着的正方形,不方便处理.d=|xi-xj|+|yi-yj ...

  3. 【AtCoder】ARC 081 E - Don't Be a Subsequence

    [题意]给定长度为n(<=2*10^5)的字符串,求最短的字典序最小的非子序列字符串. http://arc081.contest.atcoder.jp/tasks/arc081_c [算法]字 ...

  4. 【AtCoder】AGC022 F - Leftmost Ball 计数DP

    [题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...

  5. 【AtCoder】AGC005 F - Many Easy Problems 排列组合+NTT

    [题目]F - Many Easy Problems [题意]给定n个点的树,定义S为大小为k的点集,则f(S)为最小的包含点集S的连通块大小,求k=1~n时的所有点集f(S)的和取模92484403 ...

  6. 【AtCoder】ARC067 F - Yakiniku Restaurants 单调栈+矩阵差分

    [题目]F - Yakiniku Restaurants [题意]给定n和m,有n个饭店和m张票,给出Ai表示从饭店i到i+1的距离,给出矩阵B(i,j)表示在第i家饭店使用票j的收益,求任选起点和终 ...

  7. 【AtCoder】ARC095 E - Symmetric Grid 模拟

    [题目]E - Symmetric Grid [题意]给定n*m的小写字母矩阵,求是否能通过若干行互换和列互换使得矩阵中心对称.n,m<=12. [算法]模拟 [题解]首先行列操作独立,如果已确 ...

  8. 【Atcoder】AGC022 C - Remainder Game 搜索

    [题目]C - Remainder Game [题意]给定n个数字的序列A,每次可以选择一个数字k并选择一些数字对k取模,花费2^k的代价.要求最终变成序列B,求最小代价或无解.n<=50,0& ...

  9. 【Atcoder】AGC 020 B - Ice Rink Game 递推

    [题意]n个人进行游戏,每轮只保留最大的a[i]倍数的人,最后一轮过后剩余2人,求最小和最大的n,或-1.n<=10^5. [算法]递推||二分 [题解]令L(i),R(i)表示第i轮过后的最小 ...

随机推荐

  1. Django-常用异常

    1 from rest_framework.authentication import BasicAuthentication raise AuthenticationFailed(res.dict) ...

  2. ansible-cmdb 解析(ansible all -m setup )收集过来的信息并以html方式显示。

    首先安装 ansible-cmdb 直接pip install ansible-cmdb 安装 然后执行收集信息命令 ansible all -m setup >/tmp/out/ 修改下ans ...

  3. Django基础之ModelForm

    1. form与model的终极结合 class BookForm(forms.ModelForm): class Meta: model = models.Book fields = "_ ...

  4. easyUI的c if

    {field:'domdistrict2',title:'区县',width:100}, {field:'option',title:'操作',width:fixWidth(0.08),align:' ...

  5. 异步机制 - Overlapped

    1 前面说到 GetOverlappedResult的bWait含义 GetOverlappedResult的bWait含义表示是否需要等待,如果IO还处于PENDING状态,内部大概实现是这样 hO ...

  6. IdentityServer4入门一

    这几天学习IdentityServer4,感觉内容有点乱,也可能自己水平有限吧.但为了巩固学习的内容,也打算自己理一下思路. 首先IdentityServer解决什么问题? 下图是我们的一个程序的组织 ...

  7. 安装 PostgreSQL 时丢失 libintl-8.dll 解决方案

     发表于 2013 年 11 月 13 日     修订于 2018 年 05 月 05 日 PostgreSQL 比 MySQL 有更多的高级特性,而且微信支付的数据库也是基于 PostgreSQL ...

  8. 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 ...

  9. CSS — 隐藏滚动条,依旧可以滚动

    公司的系统,在PC端可以管理我们的公众号,在发布模块页面时有一个预览功能,呈现页面在手机端的样式. 做法很简单,一会就完成了,但是在预览内容过长时手机外框会有一个滚动条,影响美观,于是就想把它去掉,有 ...

  10. laydate V5-0-8动态设置min值

    laydate通过设置min,max值来对用户输入的时间做约束 laydate v1.0版本 //日期插件 var start={ elem:"#start", format:&q ...