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。

//Author: RingweEH
const ll mod=998244353; int main()
{
ll A=read(),B=read(),C=read();
A%=mod; B%=mod; C%=mod;
A=A*(A+1)/2%mod; B=B*(B+1)/2%mod; C=(C*(C+1))/2%mod;
ll ans=A*B%mod*C%mod;
printf( "%lld",ans );
}

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.

//Author:RingweEH
ll n,k;
ll calc( ll n,ll k )
{
if ( k<2 ) return 0;
if ( k>2*n ) return 0;
return min( k-1,2*n+1-k );
} int main()
{
n=read(); k=read();
ll ans=0;
for ( int i=2; i<=2*n; i++ )
ans=ans+calc( n,i )*calc( n,i-k );
printf( "%lld",ans );
}

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 就连边,会发现凡是联通块内点都能任意互换。

A-B-C => B-A-C => B-C-A => C-B-A

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

Code

赛时用时 40min.

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

//Author:RingweEH
//由于代码具有强对称性,删减了部分 copy 的函数使得代码看上去更加简短(
int find_r( int x )
{
return x==fa_r[x] ? x : fa_r[x]=find_r( fa_r[x] );
} void merge_r( int x,int y )
{
int fx=find_r(x),fy=find_r(y);
if ( fx==fy ) return;
fa_r[fx]=fy;
} void init()
{
fac[0]=1;
for ( int i=1; i<=50; i++ )
fac[i]=fac[i-1]*i%mod;
} int main()
{
for ( int i=1; i<=n; i++ )
fa_c[i]=i,fa_r[i]=i;
for ( int i=1; i<=n; i++ )
for ( int j=i+1; j<=n; j++ )
{
bool fl=1;
for ( int k=1; k<=n; k++ )
if ( a[k][i]+a[k][j]>K ) fl=0;
if ( fl ) merge_r( i,j );
}
memset( cntr,0,sizeof(cntr) ); memset( cntc,0,sizeof(cntc) );
for ( int i=1; i<=n; i++ )
cntr[find_r(i)]++,cntc[find_c(i)]++;
ll ans1=1,ans2=1; init();
for ( int i=1; i<=n; i++ )
{
if ( cntr[i]>1 ) ans1=(ans1*fac[cntr[i]])%mod;
if ( cntc[i]>1 ) ans2=(ans2*fac[cntc[i]])%mod;
} printf( "%lld\n",ans1*ans2%mod );
}

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

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

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又写错了一次边界……

//Author: RingweEH
for ( int i=2; i<=10; i++ )
{
a[i-1]=b[i];
for ( int j=i; j<=n; j++ )
cnt[a[j]=mex[a[j]][a[j-1]]]++;
b[i]=a[i];
for ( int j=i+1; j<=n; j++ )
cnt[b[j]=mex[b[j]][b[j-1]]]++;
}

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

//Author: RingweEH
void add( int u,int v,int w )
{
e[tot].to=v; e[tot].nxt=head[u]; head[u]=tot; e[tot].val=w; tot++;
if ( tot&1 ) add( v,u,0 );
} bool bfs()
{
memset( dis,inf,sizeof(dis) ); dis[0]=0; q.push( 0 );
while ( !q.empty() )
{
int u=q.front(); q.pop();
for ( int i=head[u]; i!=-1; i=e[i].nxt )
{
int v=e[i].to;
if ( !e[i].val || (dis[v]!=inf) ) continue;
dis[v]=dis[u]+1; q.push( v );
}
}
return dis[2*n+1]!=inf;
} int dfs( int u,int res )
{
if ( u>2*n ) return res;
for ( int i=head[u]; i!=-1; i=e[i].nxt )
{
int v=e[i].to;
if ( !e[i].val || (dis[v]!=dis[u]+1) ) continue;
int tmp=dfs( v,min(res,e[i].val) );
if ( tmp ) { e[i].val-=tmp,e[i^1].val+=tmp; return tmp; }
}
return 0;
} int Dinic()
{
int num,res=0;
while ( bfs() )
while ( num=dfs( 0,inf ) ) res+=num;
return res;
} int main()
{
n=read(); m=read();
for ( int i=1; i<=n; i++ )
a[i]=read(); memset( head,-1,sizeof(head) ); int ans=0;
for ( int i=1,x; i<=n; i++ )
{
x=read(); ans+=abs(x);
add( i,i+n,abs(x)+a[i] );
if ( x>=0 ) add( 0,i,2*x );
else add( i+n,2*n+1,-2*x);
}
for ( int i=1,u,v; i<=m; i++ )
u=read(),v=read(),add( u+n,v,inf ),add( v+n,u,inf ); printf( "%d\n",ans-Dinic() );
}

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. K最邻近分类

    最邻近分类是分类方法中比较简单的一种,下面对其进行介绍 1.模型结构说明        最邻近分类模型属于"基于记忆"的非参数局部模型,这种模型并不是立即利用训练数据建立模型,数据 ...

  2. kernel——Makefile, head.S ...

    在Makefile中找到的重要信息: (1)连接脚本 通过连接脚本,知道的信息: (1)入口符号 stext (2)入口连接地址 0xC0000000 + 0x00008000 根据入口符号,可以找到 ...

  3. TypeError: Cannot read property 'Component' of undefined

    继续跟着阮一峰的教程走,下面写到PropTypes的getDefaultProps时,又出现了问题,基于上一个createClass的报错换成了Component写法 错误描述: 解决方法:引入rea ...

  4. http请求返回ObjectJson,Array之类转换类型

    以下所说的类来自:package com.alibaba.fastjson 1,形如以下返回,其实是个json的map形式的返回 { "success": true, " ...

  5. (7)ASP.NET Core3.1 Ocelot Swagger

    1.前言 前端与后端的联系更多是通过API接口对接,API文档变成了前后端开发人员联系的纽带,开始变得越来越重要,而Swagger就是一款让你更好的书写规范API文档的框架.在Ocelot Swagg ...

  6. vue 常见记录

    # vuex在组件中如何获取vuex的state对象中的属性 https://blog.csdn.net/gavincz/article/details/81049461 # vuex全局变量使用 h ...

  7. 用OCR文字识别工具来审阅和处理PDF内容

    "工作的时候要同时打开好几个软件真的是太不方便了."很多公司白领都有这样的困扰.他们抱怨着进行文字识别过后又要打开文档编辑器来进行编辑.PDF是办公文档常用的格式, ABBYY F ...

  8. JUC并发工具包之CyclicBarrier & CountDownLatch的异同

    1.介绍 本文我们将比较一下CyclicBarrier和CountDownLatch并了解两者的相似与不同. 2.两者是什么 当谈到并发,将这两者概念化的去解释两者是做什么的,这其实是一件很有挑战的事 ...

  9. 设置searchDisplayController的searchResultsTableView的UITableViewStyle为grouped

    [self.searchDisplayController setValue:[NSNumber numberWithInt:UITableViewStyleGrouped] forKey:@&quo ...

  10. Unable to locate package python3 错误解决办法

    错误 huny@DESKTOP-N1EBKQP:/mnt/c/Users/Administrator$ sudo apt-get install python3 Reading package lis ...