Submission #7569198


Source Code Expand

Copy
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <queue>
#define ll long long
#define space putchar(' ')
#define endl putchar('\n')
#define debug puts("------------------------")
#define F(i,x,n) for(int i=x;i<=n;++i)
#define F_(i,x,n) for(int i=x;i>=n;--i)
using namespace std;
inline void read(int &a) {a=0;int c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();a*=b; }
inline int  Rem() {int a=0,c=getchar(),b=1; while(c>'9'||c<'0') {if(c=='-')b=-1;c=getchar();} while(c>='0'&&c<='9') a=(a<<3)+(a<<1)+c-48,c=getchar();return a*=b; }
inline void write(int x) {if(x>9)write(x/10);putchar('0'+x%10);}
inline void W(int x) {if(x<0){putchar('-'),x=-x;}write(x);}
/**/
const int N=1e5+5;
ll p=998244353;
char s[N*3];
int n;ll ans=1LL;
ll R,G,B,RG,BG,RB;
/**/
int main()
{
    read(n);
    scanf("%s",s+1);
    for(int i=1;i<=n*3;i++)
    {
        if(s[i]=='R')
        {
            if(BG){ans=ans*BG%p;BG--;continue;}
            if(!B&&!G){R++;continue;}
            if(B) ans=ans*B%p,B--,RB++;
            if(G) ans=ans*G%p,G--,RG++;
        }
        if(s[i]=='G')
        {
            if(RB){ans=ans*RB%p;RB--;continue;}
            if(!R&&!B){G++;continue;}
            if(R) ans=ans*R%p,R--,RG++;
            if(B) ans=ans*B%p,B--,BG++;
        }
        if(s[i]=='B')
        {
            if(RG){ans=ans*RG%p;RG--;continue;}
            if(!R&&!G){B++;continue;}
            if(R) ans=ans*R%p,R--,RB++;
            if(G) ans=ans*G%p,G--,BG++;
        }
    }
    for(int i=1;i<=n;i++) ans=ans*i%p;
    cout<<ans;
}

Submission Info

Submission Time
Task B - RGB Balls
User chuxuan
Language C++14 (GCC 5.4.1)
Score 800
Code Size 1702 Byte
Status
Exec Time 8 ms
Memory 512 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:28:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s",s+1);
                    ^

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample01.txt, sample02.txt
All 800 / 800 sample01.txt, sample02.txt, in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in20.txt, in21.txt, in22.txt, in23.txt, sample01.txt, sample02.txt
Case Name Status Exec Time Memory
in01.txt 7 ms 512 KB
in02.txt 7 ms 512 KB
in03.txt 7 ms 512 KB
in04.txt 7 ms 512 KB
in05.txt 7 ms 512 KB
in06.txt 8 ms 512 KB
in07.txt 8 ms 512 KB
in08.txt 7 ms 512 KB
in09.txt 8 ms 512 KB
in10.txt 7 ms 512 KB
in11.txt 8 ms 512 KB
in12.txt 8 ms 512 KB
in13.txt 8 ms 512 KB
in14.txt 7 ms 512 KB
in15.txt 7 ms 512 KB
in16.txt 7 ms 512 KB
in17.txt 7 ms 512 KB
in18.txt 8 ms 512 KB
in19.txt 7 ms 512 KB
in20.txt 8 ms 512 KB
in21.txt 8 ms 512 KB
in22.txt 7 ms 512 KB
in23.txt 7 ms 512 KB
sample01.txt 1 ms 256 KB
sample02.txt 1 ms 256 KB