D - RGB Triplets

Posted asunayi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了D - RGB Triplets相关的知识,希望对你有一定的参考价值。

 


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的主要内容,如果未能解决你的问题,请参考以下文章

ABC162D RGB Triplets

POJ - 3244-Difference between Triplets

将 OpenGL 片段着色器设置为仅通过漫反射减少 vec4 色点的 RGB 值,而不是 alpha

纹理中的 OpenGL 片段着色器

[LeetCode] 1899. Merge Triplets to Form Target Triplet

target triplets