/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Wrong Answer 2ms 320.0 KiB
#2 Wrong Answer 2ms 568.0 KiB

Code

#include<stdio.h>
#include<string.h>

int prime(int x)
{
    if(x<=1)
    {
        return 0;
    }
    for(int i=2;i*i<=x;i++){
        if(x%i==0){
            return 0;
        }
    }
    return 1;
}

int operations(int n, char *s)
{
    int a=0, b=0, c=0;
    for(int i=0;i<n;i++){
        if(s[i]=='a'){
            a++;
        }
        else if(s[i]=='b'){
            b++;
        }
        else if(s[i]=='c'){
            c++;
        }
    }

    int op=0;
    if(!prime(a)){
        if(a>0){
            op++;
        }
        else{
            op=-1;
        }
    }
    if(!prime(b)){
        if(b>0){
            op++;
        }
        else{
            op=-1;
        }
    }
    if(!prime(c)){
        if(c>0){
            op++;
        }
        else{
            op=-1;
        }
    }
    return op;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        char s[n];
        scanf("%s",s);
        printf("%d\n",operations(n,s));
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1158 Yet another Beautiful String
Contest
Happy New Year 2025
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-02 16:10:53
Judged At
2025-01-02 16:10:53
Judged By
Score
0
Total Time
2ms
Peak Memory
568.0 KiB