#include<bits/stdc++.h>using namespace std;char s[200007];int ans[200007];int main(){    int n,k;    int i=0,j=0,l=0;    scanf("%d%d",&n,&k);    scanf("%s",s+1);    for(i=1;i<=n;i++)        if(s[i]=='A')            ans…
#define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;int col[207],s[207],n;char ss[207][207];int bfs(int x){ int l=0,r=0; for(int i=1;i<=n;i++) col[i]=0; s[++r]=x; col[x]=1; while(l<r){ x=s[++l]; for(int i=1;i<=n;i++) if(s…
AtCoder Grand Contest 019 B - Reverse and Compare 题意:给定字符串,可以选定任意i.j且i<=j(当然i==j时没啥卵用),然后翻转i到j的字符串,问能组成多少种不同的字符串. tourist出的题..感觉好棒,虽然简单,但我就是不知道怎么弄,感觉思维好匮乏. 首先,如果Si=Sj,那么反转i到j和翻转i+1到j-1是一样的,也就是这种翻转不会贡献更多的答案.那么其实只要求i<j且Si!=Sj的个数就行了,当然,本身不变也是一种答案.求解i&l…
题目传送门 典型的 Atcoder 风格的计数 dp. 题目可以转化为每次在序列中插入一个 \([1,k]\) 的数,共操作 \(n\) 次,满足后一个序列的字典序严格大于前一个序列,问有多少种操作序列. 显然相同的数可以合并,因为在由相同的数 \(x\) 组成的数段中,在任何位置插入 \(x\),得到的序列都是相同的. 再考虑字典序的问题.你只能序列末尾或者一个 \(<x\) 的数前面插入 \(x\),否则得到的序列的字典序就会 \(\geq\) 原序列的字典序. 但这样问题还是比较棘手,我们…
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大值定义为三个人中第二强的人的强大值.求\(n\)组最大的强大值之和. 题解 这...不是倒着选两个人,正着选一个人构成一组就好了嘛.. #include<iostream> #include<cstdio> #include<algorithm> using namespa…
AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\).两个子序列不同当且仅当存在一种字符在两者中的出现次数不同. \(|s|\le10^5\) solution \(\prod_{i='a'}^{'z'}(\mbox{字符}i\mbox{出现的次数}+1)-1\) #include<cstdio> #include<algorithm>…
AtCoder Grand Contest 004 A - Divide a Cuboid 翻译 给定一个\(A*B*C\)的立方体,现在要把它分成两个立方体,求出他们的最小体积差. 题解 如果有一条边是偶数显然可以均分,否分沿着最长边隔开. #include<iostream> using namespace std; int a,b,c; int main() { cin>>a>>b>>c; if(a%2==0||b%2==0||c%2==0) cout…
AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\(n\)个乘客到达了飞机场,现在他们都要坐车离开机场.第\(i\)个乘客到达的时间是\(T_i\),一个乘客必须在\([T_i,T_i+k]\)时刻做到车,否则他会生气.一辆车最多可以坐\(C\)个人.问最少安排几辆车可以让所有人都不生气. 题解 从前往后贪心即可. #include<iostream…
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题解 洛谷认为此题过水,已被隐藏. #include<iostream> #include<cstdio> using namespace std; inline int read() { int x=0;bool t=false;char ch=getchar(); while((ch…
AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include<cstdio> using namespace std; #define ll long long #define MAX 100100 inline int read() { int x=0;bool t=false;char ch=getchar(); while((ch<'0'||ch>…
AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把这个数字给变成\(y\).两个按钮的作用分别是让这个数加一和把这个数取反.问最少的按按钮的次数. 题解 神仙特判题,想清楚再写. #include<iostream> using namespace std; int x,y,ans=2147483647; int main() { cin>…
AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ch[10]; int main() { scanf("%d%d",&n,&m); for(int i=1;i<=n;++i) { scanf("%s",ch+1); for(int j=1;j<=m;++j) tot+=ch[j]=='#'…
AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并且长度至少为\(n\)的最短串串长. 题解 暴力枚举\(S\)和\(T\)的重叠部分长度,然后直接\(check\) #include<iostream> #include<cstdio> #include<cstring> using namespace std; #de…
AtCoder Grand Contest 005 A - STring 翻译 给定一个只包含\(ST\)的字符串,如果出现了连续的\(ST\),就把他删去,然后所有位置前移.问最后剩下的串长. 题解 模拟栈,和维护括号一样的. #include<iostream> #include<cstring> using namespace std; #define MAX 200200 char ch[MAX]; int ans,tot; int main() { cin>>…
AtCoder Grand Contest 003 A - Wanna go back home 翻译 告诉你一个人每天向哪个方向走,你可以自定义他每天走的距离,问它能否在最后一天结束之后回到起点. 题解 什么逗逼东西... #include<cstdio> #include<cstring> using namespace std; char s[1010]; bool W,E,S,N; int main() { scanf("%s",s+1); for(in…
AtCoder Grand Contest 002 A - Range Product 翻译 告诉你\(a,b\),求\(\prod_{i=a}^b i\)是正数还是负数还是零. 题解 什么鬼玩意. #include<iostream> using namespace std; int main() { int a,b; cin>>a>>b; if(a<=0&&b>=0)cout<<"Zero"<<…
AtCoder Grand Contest 019 F-yes or no 解题思路: 考虑一个贪心策略,假设当前还有 \(x\) 道 \(\text{yes}\) 和 \(y\) 道 \(\text{no}\) ,那么一定猜较大者,如果 \(x=y\) 就相当于随便猜一个,把 \((x, y)\) 用坐标表示,把所有在这种决策下猜对的边用蓝色表示,走过这样一条边就相当于有 \(1\) 的贡献,然后会发现从 \((0,0)\) 到 \((n,m)\) 的所有路径经过的蓝色的边的数量都是相同的 \…
tourist出的题诶!想想就很高明,老年选手可能做不太动.不过A题还是按照惯例放水的. AtCoder Grand Contest 019 A: Ice Tea Store 题意:买0.25L,0.5L,1L,2L装的一瓶子茶分别需要a,b,c,d元,问买总共n L茶需要多少钱. a,b,c,d,n为整数. 显然a,b,c三种中我们智慧用min(4a,2b,c)去买1L.记m=min(4a,2b,c) 然后比较2m和d的大小以决定是否需要买2L一瓶的. 如果2m<=d,那么花费为nm. 如果2…
AtCoder Grand Contest 014 A - Cookie Exchanges 有三个人,分别有\(A,B,C\)块饼干,每次每个人都会把自己的饼干分成相等的两份然后给其他两个人.当其中有一个人的饼干数量是奇数的时候停止,求会进行几次这样子的操作,或者会永远进行下去. 首先无解的情况一定是三个数都是相等的偶数. 否则直接暴力模拟就行了.(盲猜答案不会很大) 证明一下答案的范围:不妨令\(A\le B\le C\),那么最大值和最小值之间的差就是\(C-A\),那么执行完一次操作之后…
Atcoder Grand Contest 036 D - Negative Cycle 解题思路 在某些情况下,给一张图加或删一些边要使图合法的题目要考虑到最短路的差分约束系统.这一题看似和最短路没什么关系,但有一个不那么经典的推论,对于一个点 \(u\) 不在负环上的一个充要条件是 \[ \forall_{\text{Edge }v\rightarrow u} dis(S,v)+weight(v, u)\geq dis(S,u) \] 其中 \(S\) 是图中任意与 \(u\) 联通的一点.…
A - AtCoder Group Contest Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement There are 3N participants in AtCoder Group Contest. The strength of the i-th participant is represented by an integer ai. They will form N teams,…
Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement There are 3N participants in AtCoder Group Contest. The strength of the i-th participant is represented by an integer ai. They will form N teams, each consisting of three p…
#include<bits/stdc++.h>using namespace std;int n,a,b,sum;void dfs(int x,int y,int ban){    if(__builtin_popcount(ban^sum)==1){        printf("%d %d ",y,x^y);        return;    }    for(int i=0;i<n;i++)        if((~(ban>>i)&1)&…
Atcoder 题面传送门 & 洛谷题面传送门 u1s1 Atcoder 不少思维题是真的想不出来,尽管在 Atcoder 上难度并不高 二分答案(这我倒是想到了),检验最上面一层的数是否 \(\ge x\). 我们将最底下一层的数中 \(\ge x\) 的 \(a_i\) 设为 \(1\),\(<x\) 的设为 \(0\),那么原题可以转化为每次操作对于相邻三个数,如果 \(1\) 的个数 \(\ge 2\),就在该位上填一个 \(1\),否则在该位上填一个 \(0\),求最终顶上的数是…
Atcoder 题面传送门 & 洛谷题面传送门 Yet another 思维题-- 注意到此题 \(n\) 数据范围很大,但是 \(a_i,b_i\) 数据范围很小,这能给我们什么启发呢? 观察题目所求的组合数的形式,我们可以联想到组合数的组合意义(qwq 似乎 AGC 很喜欢放组合意义的题?涨见识了/cy):\(\dbinom{x+y}{x}\) 为从 \((0,0)\) 出发,只能向上或向右走,到达 \((x,y)\) 的方案数. 于是此题可以转化为,对于 \(\forall i,j\) 求…
Atcoder 题面传送门 & 洛谷题面传送门 这是一道难度 Cu 的 AGC E,碰到这种思维题我只能说:not for me,thx 然鹅似乎 ycx 把题看错了? 首先这个平方与乘法比较喜闻乐见,很容易与组合联系在一起,于是我们不妨把题目条件翻译成组合的语言: 有一排 \(n\) 个格子,你要在其中插入若干个隔板将其隔成若干段 有 \(m\) 个特殊格子 \(a_1,a_2,\dots,a_m\),\(\forall i\in [1,m]\) 你禁止在 \(a_i\) 与 \(a_{i}+…
洛谷题面传送门 & Atcoder 题面传送门 记先手移动棋子的树为红树,后手移动棋子的树为蓝树. 首先考虑一个性质,就是如果与当前红色棋子所在的点相连的边中存在一条边,满足这条边的两个端点在蓝树上的距离 \(\ge 3\),那么答案肯定是 \(-1\),因为如果此时红色棋子与蓝色棋子在蓝树上的距离 \(\le 1\),那么先手就可以沿着这条红边将红色棋子移到该边的另一个端点,使红色棋子与蓝色棋子在蓝树上的距离 \(>1\),否则原地不动.如果后手再次将蓝色棋子移到与红色棋子在蓝树上距离为…
Time Limit: 2 sec / Memory Limit: 1024 MB Score : 400400 points Problem Statement Snuke has an empty sequence aa. He will perform NN operations on this sequence. In the ii-th operation, he chooses an integer jj satisfying 1≤j≤i1≤j≤i, and insert jj at…
#include<bits/stdc++.h>using namespace std;int a[200007];int b[200007];long long dp[200007];long long sum[200007];const long long mod =1e9+7;int main(){    dp[0]=1;    int n;    scanf("%d",&n);    for(int i=1;i<=n;i++)        scanf(…
#define HAVE_STRUCT_TIMESPEC//编译器中time.h和phread.h头文件中timespec结构体重名,故加此行#include<bits/stdc++.h>using namespace std;int a[200007],b[2000007];priority_queue<pair<int,int> >q;int n;int mi(int x){ return x==1?n:x-1;}int pl(int x){ return x==n…