码迷,mamicode.com
首页 > 其他好文 > 详细

D - RGB Triplets

时间:2020-04-14 20:41:36      阅读:78      评论:0      收藏:0      [点我收藏+]

标签:nsis   不能   html   title   ext   std   length   element   ati   

 


Time Limit: 2 sec / Memory Limit: 1024 MB

ps:我的vector需要加强,用错了。

Problem Statement

We have a string SS of length N consisting of R, G, and B.

Find the number of triples (i, j, k) (1i<j<kN) that satisfy both of the following conditions:

  • SiSj , SiSk , and SjSk .
  • jikj .

Constraints

  • 1N40001≤N≤4000
  • SS is a string of length NN consisting of R, G, and B.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of triplets in question.


Sample Input 1 Copy

Copy
4
RRGB

Sample Output 1 Copy

Copy
1

Only the triplet (1, 3, 4)(1, 3, 4) satisfies both conditions. The triplet (2, 3, 4)(2, 3, 4) satisfies the first condition but not the second, so it does not count.


Sample Input 2 Copy

Copy
39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

Sample Output 2 Copy

Copy
1800
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
const int N=2e5;
int a[4005],b[4005],c[4005];//若改为vector<int>a,b,c错误,vector不能达成a[i]用法

int main(){
int n,l=0,m=0,r=0;
ll ans=0;
string s;
cin>>n>>s;
rep(i,n){
if(s[i]==‘R‘)
    a[l++]=i+1;
if(s[i]==‘G‘)
    b[m++]=i+1;
if(s[i]==‘B‘)
    c[r++]=i+1;
}
for(int i=0;i<l;i++)
for(int j=0;j<m;j++){
    int sum=r;
    int a1=min(a[i],b[j]);
    int b1=max(a[i],b[j]);
    if(2*a1-b1-1>=0&&2*a1-b1-1<n&&s[2*a1-b1-1]==‘B‘)
        sum--;
    if(2*b1-a1-1>=0&&2*b1-a1-1<n&&s[2*b1-a1-1]==‘B‘)
        sum--;
    if((a1+b1)%2==0&&s[(a1+b1)/2-1]==‘B‘)
        sum--;
    ans+=sum;
    //cout<<ans<<endl;
}
cout<<ans<<endl;
return 0;
}

  

D - RGB Triplets

标签:nsis   不能   html   title   ext   std   length   element   ati   

原文地址:https://www.cnblogs.com/asunayi/p/12700262.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!