A. Array Factory 将下标按前缀和排序,然后双指针,维护最大的右边界即可. #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; const int N=200010; int n,i,j,anslen,ansl,ansr,mr,q[N]; ll a[N],lim; inline bool cmp(int x,int y){return a[x]<a[y];…
A. Artifact Guarding 选出的守卫需要满足$\max(a+b)\leq \sum a$,从小到大枚举每个值作为$\max(a+b)$,在权值线段树上找到最大的若干个$a$即可. 时间复杂度$O(n\log n)$. #include<cstdio> #include<algorithm> #include<set> #include<map> using namespace std; typedef long long ll; const…
A. Count The Ones $ans=b-c+1$. #include <stdio.h> using namespace std ; int a , b , c ; void solve () { printf ( "%d\n" , 1 + b - c ) ; } int main () { while ( ~scanf ( "%d%d%d" , &a , &b , &c ) ) solve () ; return 0…
A. Pieces of Parentheses 将括号串排序,先处理会使左括号数增加的串,这里面先处理减少的值少的串:再处理会使左括号数减少的串,这里面先处理差值较大的串.确定顺序之后就可以DP了. 时间复杂度$O(n^3)$. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=310,inf=1000000; int n,i,j,m,all,…
题目:Problem A. Arithmetic DerivativeInput file: standard inputOutput file: standard inputTime limit: 1 secondMemory limit: 256 mebibytesLets define an arithmetic derivative:• if p = 1 then p0 = 0;• if p is prime then p0 = 1;• if p is not prime then n0…
题目: Problem D. Great AgainInput file: standard inputOutput file: standard outputTime limit: 2 secondsMemory limit: 512 megabytesThe election in Berland is coming. The party United Berland is going to use its influence to win themagain. The crucial co…
题目:Problem K. PiecemakingInput file: standard inputOutput file: standard outputTime limit: 1 secondMemory limit: 512 mebibytesThe civil war in Berland continues for five years already. The United Nation decided to end the bloodshed.Berland consists o…
题意:给你一张简单无向图(但可能不连通),再给你一个K,让你求解任意一个问题:K染色或者输出一条K长路径. 直接贪心染色,对一个点染上其相邻的点的颜色集合之中,未出现过的最小的颜色. 如果染成就染成了.如果到某个点,发现染不成,则倒着按照颜色从大到小回去,则一定恰好可以找出一条K长度的路径. #include<cstdio> #include<cstring> using namespace std; int first[1005],next[20005],v[20005],e,c…
题意:有n个土豆,每个有体积V(i),你可以将每个土豆等分为不超过K份,问你最大块和最小块比值最小为多少. 直接枚举切法,只有n*K种,然后保证其为最大块,去算其他块的切法,即让其他块切得尽可能大即可.O(n*n*K). #include<cstdio> #include<cstring> using namespace std; int n,K,a[105],ans1=150,ans2=1,x[105],ansx[105]; int main(){ // freopen(&quo…
题目: Problem F. Matrix GameInput file: standard inputOutput file: standard inputTime limit: 1 secondMemory limit: 256 mebibytesAlice and Bob are playing the next game. Both have same matrix N × M filled with digits from 0 to 9.Alice cuts the matrix ve…
题目:Problem J. TerminalInput file: standard inputOutput file: standard inputTime limit: 2 secondsMemory limit: 256 mebibytesN programmers from M teams are waiting at the terminal of airport. There are two shuttles at the exitof terminal, each shuttle…
题目:Problem L. Canonical duelInput file: standard inputOutput file: standard outputTime limit: 2 secondsMemory limit: 256 megabytesIn the game «Canonical duel» board N × M is used. Some of the cells of the board contain turrets. Aturret is the unit wi…
题目:Problem D. Clones and TreasuresInput file: standard inputOutput file: standard outputTime limit: 1 secondMemory limit: 256 mebibytesThe magical treasury consists of n sequential rooms. Due to construction of treasury its impossible togo from room…
有两辆车,容量都为K,有n(10w)个人被划分成m(2k)组,依次上车,每个人上车花一秒.每一组的人都要上同一辆车,一辆车的等待时间是其停留时间*其载的人数,问最小的两辆车的总等待时间. 是f(i,j)表示前i组,j个人是否可行.w(i)表示第i组的人数. if f(i,j)==1 then f(i+1,j+w(i+1))=1. 这是个bitset可以做的事情,每次左移以后或上f(i-1)的bitset即可.其实可以滚动数组. 然后每更新一次bitset,求一下其最左侧的1的位置,就是对于第一辆…
A. Survival Route 留坑. B. Dispersed parentheses $f[i][j][k]$表示长度为$i$,未匹配的左括号数为$j$,最多的未匹配左括号数为$k$的方案数.时间复杂度$O(n^3)$. #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; const int P=1000000009; const int N=310; int n,m…
A. Associated Vertices 首先求出SCC然后缩点,第一次求出每个点能到的点集,第二次收集这些点集即可,用bitset加速,时间复杂度$O(\frac{nm}{64})$. #include<cstdio> #include<bitset> using namespace std; const int N=10010; int n,m,x,y,i,j,g[N],G[N],v[N*3],V[N*3],nxt[N*3],NXT[N*3],ed; int vis[N],…
A. (a, b)-Tower 当指数大于模数的时候用欧拉定理递归计算,否则直接暴力计算. #include<cstdio> #include<algorithm> #include<cmath> #include<string> #include<iostream> using namespace std; typedef long long LL; int pw(int x,int y,int mod){ int ret=1; for(int…