Contest Link

Official Editorial

比赛体验良好,网站全程没有挂。题面简洁好评,题目质量好评。对于我这个蒟蒻来说非常合适的一套题目。

A. Simple Math

Problem Link

Description

Given are three positive integers \(A,B,\) and \(C\) . Compute the following value modulo \(998244353:\sum_{a=1}^A\sum_{b=1}^B\sum_{c=1}^C a\times b\times c.\)

\(1\leq A,B,C\leq 1e9\)

Solution

\[\sum_{a=1}^A\sum_{b=1}^B\sum_{c=1}^C a\times b\times c
= \sum_{a=1}^A a\sum_{b=1}^B b\sum_{c=1}^C c
\]

疯狂取模就好了。

Code

赛时用时 5min。

  1. //Author: RingweEH
  2. const ll mod=998244353;
  3. int main()
  4. {
  5. ll A=read(),B=read(),C=read();
  6. A%=mod; B%=mod; C%=mod;
  7. A=A*(A+1)/2%mod; B=B*(B+1)/2%mod; C=(C*(C+1))/2%mod;
  8. ll ans=A*B%mod*C%mod;
  9. printf( "%lld",ans );
  10. }

B. Quadruple

Problem Link

Description

Given are integers \(N\) and \(K\) . How many quadruples of integers \((a,b,c,d)\) satisfy both of the following conditions?

  • \(1\leq a,b,c,d\leq N\)
  • \(a+b-c-d=K\)

\(1\leq N\leq 1e5,-2(N-1)\leq K\leq 2(N-1)\)

Solution

暴力枚举显然非常的不可行。按照正负,把原来的式子分成两部分:

  • \(a+b=x\)
  • \(c+d=x-K\)

然后对于每一部分,设 \(f(N,K)\) 表示 \(1\leq a,b\leq N\) 时 \(a+b=K\) 的方案数。于是得到:

\[f(N,K)=\min(K-1,2\times N+1-K)
\]

然后 \(O(N)\) 算一下就好了。不过容斥可以做到 \(O(1)\) 。

注意特判 \(f(N,K)\) 中 \(K\) 不合法的情况。

Code

赛时用时 40min.

  1. //Author:RingweEH
  2. ll n,k;
  3. ll calc( ll n,ll k )
  4. {
  5. if ( k<2 ) return 0;
  6. if ( k>2*n ) return 0;
  7. return min( k-1,2*n+1-k );
  8. }
  9. int main()
  10. {
  11. n=read(); k=read();
  12. ll ans=0;
  13. for ( int i=2; i<=2*n; i++ )
  14. ans=ans+calc( n,i )*calc( n,i-k );
  15. printf( "%lld",ans );
  16. }

C. Shuffle Permutation

Problem Link

Description

Given are an \(N\times N\) matrix and an integer \(K\). The entry in the \(i\)-th row and \(j\)-th column of this matrix is denoted as \(a_{i,j}\) . This matrix contains each of \(1,2,...,N^2\) exactly once.

Sigma can repeat the following two kinds of operation arbitrarily many times in any order.

  • Pick two integers \(x,y(1\leq x<y\leq N)\) that satisfy \(a_{i,x}+a_{i,y}\leq K\) for all \(i(1\leq i\leq N)\) and swap the \(x\)-th and the \(y\)-th columns.
  • Pick two integers \(x,y(1\leq x<y\leq N)\) that satisfy \(a_{x,i}+a_{y,i}\leq K\) for all \(i(1\leq i\leq N)\) and swap the \(x\)-th and the \(y\)-th rows.

How many matrices can he obtain by these operations?Find it modulo \(998244353.\)

\(1\leq N\leq 50. 1\leq K\leq 2\times N^2.\)

Solution

啥都不知道,开始手模样例。

3min之后……发现自己是个思博。显然行列之间没什么关系。所以乘起来就好了。

然后呢?还是不知道行列怎么算。

仔细思考时候发现,如果把行(或者列)当成点,能够 swap 就连边,会发现凡是联通块内点都能任意互换。

  1. A-B-C => B-A-C => B-C-A => C-B-A

以上是列的 \(N=3\) 情况。那么只需要暴力枚举判断加边,带权并查集就好了(事实上直接统计也行)。

Code

赛时用时 40min.

WA 了一发,原因是把计算行/列的情况中乘法原理搞成了加法……就这还能 AC \(\dfrac{22}{25}\) ……没话讲。

  1. //Author:RingweEH
  2. //由于代码具有强对称性,删减了部分 copy 的函数使得代码看上去更加简短(
  3. int find_r( int x )
  4. {
  5. return x==fa_r[x] ? x : fa_r[x]=find_r( fa_r[x] );
  6. }
  7. void merge_r( int x,int y )
  8. {
  9. int fx=find_r(x),fy=find_r(y);
  10. if ( fx==fy ) return;
  11. fa_r[fx]=fy;
  12. }
  13. void init()
  14. {
  15. fac[0]=1;
  16. for ( int i=1; i<=50; i++ )
  17. fac[i]=fac[i-1]*i%mod;
  18. }
  19. int main()
  20. {
  21. for ( int i=1; i<=n; i++ )
  22. fa_c[i]=i,fa_r[i]=i;
  23. for ( int i=1; i<=n; i++ )
  24. for ( int j=i+1; j<=n; j++ )
  25. {
  26. bool fl=1;
  27. for ( int k=1; k<=n; k++ )
  28. if ( a[k][i]+a[k][j]>K ) fl=0;
  29. if ( fl ) merge_r( i,j );
  30. }
  31. memset( cntr,0,sizeof(cntr) ); memset( cntc,0,sizeof(cntc) );
  32. for ( int i=1; i<=n; i++ )
  33. cntr[find_r(i)]++,cntc[find_c(i)]++;
  34. ll ans1=1,ans2=1; init();
  35. for ( int i=1; i<=n; i++ )
  36. {
  37. if ( cntr[i]>1 ) ans1=(ans1*fac[cntr[i]])%mod;
  38. if ( cntc[i]>1 ) ans2=(ans2*fac[cntc[i]])%mod;
  39. }
  40. printf( "%lld\n",ans1*ans2%mod );
  41. }

D.Number of Multisets

Problem Link

Description

You are given two positive integers \(N\) and \(K\) . How many multisets of raional numbers satisfy all of the following conditions?

  • The multiset has exactly \(N\) elements and the sum of them is equal to \(K\).
  • Each element of the multiset is one of \(1,\dfrac{1}{2},\dfrac{1}{4},...\) . In other words,each element can be represented as \(\dfrac{1}{2^i}(i=0,1,...)\)

The answer may be large,so print it modulo \(998244353.\)

Solution

小清新分讨DP题。

分为两类:用 \(1\) 的和不用的。

对于用了至少一个 \(1\) 的,\(f[i][j]=f[i-1][j-1]\)

对于没有用 \(1\) 的,\(f[i][j]=f[i][2\times j]\)

显然把所有元素乘2就是等价的了。

综上, \(f[i][j]=f[i-1][j-1]+f[i][2\times j]\).

最后考虑边界就好了: \(f[i][j]=0(i<j)\)

时间复杂度 \(O(N^2)\)

Code

  1. //Author: RingweEH
  2. int main()
  3. {
  4. n=read(); k=read();
  5. f[0][0]=1;
  6. for ( int i=1; i<=n; i++ )
  7. for ( int j=i; j; j-- )
  8. f[i][j]=(f[i-1][j-1]+(j*2>i ? 0 : f[i][j*2]) )%mod;
  9. printf( "%lld",f[n][k] );
  10. }

E. Mex Mat

Problem Link

Description

Consideer an \(N\times N\) matrix, Let us denote by \(a_{i,j}\) the entry in the \(i\)-th row and \(j\)-th column. For \(a_{i,j}\) where \(i=1\) or \(j=1\) holds,its value is one of \(0,1,2\) and given in the input. The remaining entries are defined as follows:

  • \(a_{i,j}=mex(a_{i-1,j},a_{i,j-1})(2\leq i,j\leq N)\)

( \(mex\) 定义见题面)

How many entries of the matrix are \(0,1,2\) respectively ?

Solution

一开始看成了SG函数的那个 mex emmm

神仙结论题……官方题解简洁而优雅 暴力 。

官方题解给了一个 \(20\times 20\) 的随机矩阵的完整形式,然后发现在 \(i>4,j>4\) 之后都有 \(a_{i,j}=a_{i-1,j-1}\) ,暴力跑前面的四行四列即可。

证明……你可以暴力跑 \(n=5\) 的矩阵,然后有 \(a_{4,4}=a_{5,5}\) ,按这个性质下去就好了。

Code

REH 这个zz又写错了一次边界……

  1. //Author: RingweEH
  2. for ( int i=2; i<=10; i++ )
  3. {
  4. a[i-1]=b[i];
  5. for ( int j=i; j<=n; j++ )
  6. cnt[a[j]=mex[a[j]][a[j-1]]]++;
  7. b[i]=a[i];
  8. for ( int j=i+1; j<=n; j++ )
  9. cnt[b[j]=mex[b[j]][b[j-1]]]++;
  10. }

F. Sum of Abs

Problem Link

Description

Given is a simple undirected graph with \(N\) vertices and \(M\) edges. Its vertices are numbered \(1,2,...,N\) and its edges are numbered \(1,2,..,M\) .On Vertex \(i(1\leq i\leq N)\) two integers \(A_i\) and \(B_i\) are written. Edge \(i(1\leq i\leq M)\) connects Vertices \(U_i\) and \(V_i\) .

Snuke picks zero or more vertices and delete them. Deleting Vertex \(i\) costs \(A_i\) . When a vertex is deleted,edges that are incident to the vertex are also deleted. The score after deleting vertices is calculated as follows:

  • The score is the sum of the scores of all connected components.
  • The score of a connected component is the absolute value of the sum of \(B_i\) of the vertices in the connected component.

Find the maxinum possible profit Snuke can gain. profit is (score)-(the sum of costs).

Solution

很好的网络流建模练习题。

简化题意:\(n\) 点 \(m\) 边的无向图,删点代价 \(A_i\) ,最大化所有连通块 \(B_i\) 之和的绝对值之和减去总代价。

价值就等价于给每个点一个系数 \(p_i=\pm 1\) ,使得 \(\forall (x,y)\in E,p_x=p_y\) 的最大的 \(\sum_{i=1}^n p_ib_i\)

考虑网络流建图:将 \(b_i\) 分为正负两类, \(S\) 向正的连 \(2b_i\) 的边,负的向 \(T\) 连 \(-2b_i\) 的边,图中直接相连的两点连上 \(\infty\) (如果两点不同向,必须有一个被割掉)

再来看删除操作。可以看做这个点不要求正负,且不帮助连边。那么进行拆点,建立一条 \((i,i+n)\in E'\) ,流量为 \(a_i+|b_i|\) 表示删除的代价。

对于一条原图中的边,连 \((x+n,y),(y+n,x)\) ,此时若 \((x,x+n)\) 被删掉,那么 \(x\) 就到不了 \(y+n\) .

最终答案就是 \(\sum_{i=1}^n |b_i|\) 减去最小割。

Code

  1. //Author: RingweEH
  2. void add( int u,int v,int w )
  3. {
  4. e[tot].to=v; e[tot].nxt=head[u]; head[u]=tot; e[tot].val=w; tot++;
  5. if ( tot&1 ) add( v,u,0 );
  6. }
  7. bool bfs()
  8. {
  9. memset( dis,inf,sizeof(dis) ); dis[0]=0; q.push( 0 );
  10. while ( !q.empty() )
  11. {
  12. int u=q.front(); q.pop();
  13. for ( int i=head[u]; i!=-1; i=e[i].nxt )
  14. {
  15. int v=e[i].to;
  16. if ( !e[i].val || (dis[v]!=inf) ) continue;
  17. dis[v]=dis[u]+1; q.push( v );
  18. }
  19. }
  20. return dis[2*n+1]!=inf;
  21. }
  22. int dfs( int u,int res )
  23. {
  24. if ( u>2*n ) return res;
  25. for ( int i=head[u]; i!=-1; i=e[i].nxt )
  26. {
  27. int v=e[i].to;
  28. if ( !e[i].val || (dis[v]!=dis[u]+1) ) continue;
  29. int tmp=dfs( v,min(res,e[i].val) );
  30. if ( tmp ) { e[i].val-=tmp,e[i^1].val+=tmp; return tmp; }
  31. }
  32. return 0;
  33. }
  34. int Dinic()
  35. {
  36. int num,res=0;
  37. while ( bfs() )
  38. while ( num=dfs( 0,inf ) ) res+=num;
  39. return res;
  40. }
  41. int main()
  42. {
  43. n=read(); m=read();
  44. for ( int i=1; i<=n; i++ )
  45. a[i]=read();
  46. memset( head,-1,sizeof(head) ); int ans=0;
  47. for ( int i=1,x; i<=n; i++ )
  48. {
  49. x=read(); ans+=abs(x);
  50. add( i,i+n,abs(x)+a[i] );
  51. if ( x>=0 ) add( 0,i,2*x );
  52. else add( i+n,2*n+1,-2*x);
  53. }
  54. for ( int i=1,u,v; i<=m; i++ )
  55. u=read(),v=read(),add( u+n,v,inf ),add( v+n,u,inf );
  56. printf( "%d\n",ans-Dinic() );
  57. }

AtCoder Regular Contest 107(VP)的更多相关文章

  1. AtCoder Regular Contest 061

    AtCoder Regular Contest 061 C.Many Formulas 题意 给长度不超过\(10\)且由\(0\)到\(9\)数字组成的串S. 可以在两数字间放\(+\)号. 求所有 ...

  2. AtCoder Regular Contest 094 (ARC094) CDE题解

    原文链接http://www.cnblogs.com/zhouzhendong/p/8735114.html $AtCoder\ Regular\ Contest\ 094(ARC094)\ CDE$ ...

  3. AtCoder Regular Contest 092

    AtCoder Regular Contest 092 C - 2D Plane 2N Points 题意: 二维平面上给了\(2N\)个点,其中\(N\)个是\(A\)类点,\(N\)个是\(B\) ...

  4. AtCoder Regular Contest 093

    AtCoder Regular Contest 093 C - Traveling Plan 题意: 给定n个点,求出删去i号点时,按顺序从起点到一号点走到n号点最后回到起点所走的路程是多少. \(n ...

  5. AtCoder Regular Contest 094

    AtCoder Regular Contest 094 C - Same Integers 题意: 给定\(a,b,c\)三个数,可以进行两个操作:1.把一个数+2:2.把任意两个数+1.求最少需要几 ...

  6. AtCoder Regular Contest 095

    AtCoder Regular Contest 095 C - Many Medians 题意: 给出n个数,求出去掉第i个数之后所有数的中位数,保证n是偶数. \(n\le 200000\) 分析: ...

  7. AtCoder Regular Contest 102

    AtCoder Regular Contest 102 C - Triangular Relationship 题意: 给出n,k求有多少个不大于n的三元组,使其中两两数字的和都是k的倍数,数字可以重 ...

  8. AtCoder Regular Contest 096

    AtCoder Regular Contest 096 C - Many Medians 题意: 有A,B两种匹萨和三种购买方案,买一个A,买一个B,买半个A和半个B,花费分别为a,b,c. 求买X个 ...

  9. AtCoder Regular Contest 097

    AtCoder Regular Contest 097 C - K-th Substring 题意: 求一个长度小于等于5000的字符串的第K小子串,相同子串算一个. K<=5. 分析: 一眼看 ...

随机推荐

  1. http 怎样关闭

    如何优雅的关闭关闭这个fd , 如果只是一个简单的fd 直接调用close 就行, 但是如果要是一个框架 那就接到 资源回收复用 内存泄漏等问题: 来看看 ngx 是用怎样的思路处理 事务结束动作: ...

  2. TextView之富文本

    项目中使用富文本比较常见了,一行显示多种样式颜色的文本,使用 ClickableSpan 富文本实现在同一个 TextView 中的文本的颜色.大小.背景色等属性的多样化和个性化. 我们也可以使用Ht ...

  3. Docker安装Oracle11g

    为什么使用docker安装oracle,因为自己搭建配置的话可能时间太久太繁琐等等原因,也因为docker实在太方便了 本文主要是使用docker-compose安装Oracle 11g,因为使用do ...

  4. 编译的Ceph二进制文件过大问题

    前言 在ceph的研发群里看到一个cepher提出一个问题,编译的ceph的二进制文件过大,因为我一直用的打包好的rpm包,没有关注这个问题,重新编译了一遍发现确实有这个问题 本篇就是记录如何解决这个 ...

  5. 通过ceph-deploy安装不同版本ceph

    之前有在论坛写了怎么用 yum 安装 ceph,但是看到ceph社区的群里还是有人经常用 ceph-deploy 进行安装,然后会出现各种不可控的情况,虽然不建议用ceph-deploy安装,但是既然 ...

  6. dpkg 批量卸载

    dpkg -l |grep deepin|awk '{print $2}'|xargs sudo dpkg -P

  7. WinRM服务远程命令执行

    WinRM服务简介 WinRM是WindowsRemoteManagementd(win远程管理)的简称.基于Web服务管理(WS-Management)标准,使用80端口或者443端口.这样一来,我 ...

  8. Hash算法——加密解密说明

    MD5 pmd5-md5加密解密 加密类型识别工具 hash-identifier

  9. SpringBoot使用策略模式+工厂模式

    为了防止大量的if...else...或switch case代码的出现,可以使用策略模式+工厂模式进行优化. 在我的项目当中,报表繁多,所以尝试了这种方式进行优化报表的架构.代码很简单,如下: Fa ...

  10. CDR排钻教程-CorelDRAW服装设计中的排钻技术

    服装设计一直都是一个很火热的行业,也是一个比较高端的行业,随着时代的步伐,以前的人都是用手绘的方式来设计服装,现在不一样了,电脑可以说普及到了每一个家庭,让软件以更快的速度,更准确的数据来设计服装中的 ...