首页 > 其他分享 >Educational Codeforces Round 123 E

Educational Codeforces Round 123 E

时间:2022-09-02 20:12:09浏览次数:42  
标签:Educational flagd rr int Codeforces 123 flagr ans define

E. Expand the Path

我们画出一个合法的一般性的来研究 比如RDRDR
我们可以将其任意一个往下 往右延长 但是这个图形获得的面积是不规则的 但是我们知道 合法的序列肯定是只能往下往右的 我们的线移动的距离一定 那么获得的面积也肯定是个矩形 从而移动一下即可 我们只需要记录拐角点在哪即可
注意要加上本来的长度 拐角点还要再加上前一个点

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+20;
const int M = 998244353;
const int mod = 998244353;
#define int long long
#define endl '\n'
#define Endl '\n'
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define _ 0
#define inf 0x3f3f3f3f3f3f3f3f
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);

void solve() {
    int n;cin>>n;
    string s;cin>>s;
    int dd=1,rr=1,d=0,r=0,flagd=0,flagr=0;
    for(auto c:s){
        if(c=='D')dd++,flagd=1;
        else rr++,flagr=1;
        if(c=='D'&&flagr)d++;
        if(c=='R'&&flagd)r++;
    }
    int ans=s.size()+1;
    if(flagd)ans+=(r+1)*(n-dd);
    if(flagr)ans+=(d+1)*(n-rr);
    if(flagd&&flagr)ans+=(n-rr)*(n-dd);
    cout<<ans<<endl;
}
signed main(){
    fast
    int T;cin>>T;
    while(T--) {
        solve();
    }
    return ~~(0^_^0);
}

标签:Educational,flagd,rr,int,Codeforces,123,flagr,ans,define
From: https://www.cnblogs.com/ycllz/p/16651088.html

相关文章

  • Codeforces Round #814 (Div. 2)
    Preface关于军训……它死了第一次感觉到疫情的好处,就是不知道训了一半给不给学分,要不要补训一直打隔膜颓废也不是办法,因此来写写题(才不是因为路由器没到舍不得用流量更......
  • Educational Codeforces Round 134 (Rated for Div. 2) D Maximum AND
    MaximumAND贪心从高位开始,尽可能地让\(a\)中该位为\(0\)的和\(b\)中该位为\(1\)的配对在一起,换句话说,可以让\(a\)由小到大排序,\(b\)由大到小排序如果当......
  • codeforces极简题解
    CF1713F利用lucas定理,\(b_S\)表示下标\(T\)与\(S\)无交的\(a_T\)的异或,由于部分\(b_S\)未知,不能直接iFWT。回顾容斥:\([S=\emptyset]=\sum_{T\subseteqS}(-1)^|T|\),\([n=0......
  • Codeforces Round #773 E
    AnonymityIsImportant我们最开始会想到用三个状态表示其实并不用我们只需要用0表示这个人没病1表示不确定有病(这样我们就可以用set来做了)要是一个区间给了有病我们......
  • Educational Codeforces Round 134 (Rated for Div. 2)
    DMaxiumAnd贪心,优先满足高位,每次判断是否能够满足这一位答案为1,如果能则更新答案,这样显然是优的EPrefixFunction模仿求前缀函数的算法,先预处理求出\(|S|\)的前缀函......
  • Educational Codeforces Round 134 (Rated for Div. 2)
    EducationalCodeforcesRound134(RatedforDiv.2)目录EducationalCodeforcesRound134(RatedforDiv.2)D.MaximumANDE.PrefixFunctionQueriesD.Maximum......
  • Codeforces Round #606(B-D)
     Dashboard-CodeforcesRound#606(Div.2,basedonTechnocup2020EliminationRound4)-CodeforcesB.MakeThemOdd题意:一个数组,每次选择一个数,将数组中的......
  • 使用selenium自动化模块实现登录12306
    importtimefromselenium.webdriverimportChromefromselenium.webdriver.chrome.optionsimportOptionsfromselenium.webdriver.common.byimportByfromselenium.w......
  • Codeforces Round #817 (Div. 4) ABCDEFG
    https://codeforces.com/contest/1722/problem/A#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;typedefpair<int,int>PII;constintN=200200,......
  • Codeforces Round #817 (Div. 4)
    CF传送门因为洛谷题库未更新,所以给出的题面都是CF的。现场打真是太卡了(梯子挂了,codeforc.es也崩了),所以五六分钟才打开题目\(qwq\)A.SpellCheck萌萌题,把字符串放桶里......