QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#600562#6562. First LastForever_Young#WA 0ms3944kbC++141.9kb2024-09-29 17:24:512024-09-29 17:24:52

Judging History

你现在查看的是最新测评结果

  • [2024-09-29 17:24:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3944kb
  • [2024-09-29 17:24:51]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define data dataa
using LL=long long;
using ULL=unsigned long long;
using LD=long double;
char s[1010][20];
int g[4][4],n;
map<char,int>id;
bool check(int n,int a,int g[4][4])
{
    bool res_x=0,res;

//    for (int i=1;i<=3;i++)
//        for (int j=1;j<=3;j++) printf("%d,%d = %d\n",i,j,g[i][j]);

    int b=a%3+1,c=b%3+1;
    if (g[a][b]>g[b][a]&&g[a][c]>g[c][a]){
        if (g[b][c]<g[c][b]) swap(b,c);
    } else
    if (g[a][c]>g[c][a]) swap(b,c);

    int A=g[a][b]-g[b][a],B=g[b][c]-g[c][b],C=g[c][a]-g[a][c];
    if (A>0&&B>0&&C>0){
        int t = min(A,min(B,C));
        A-=t,B-=t,C-=t;
        res_x^=t;
    }

    int AA=g[a][a]&1,BB=g[b][b]&1,CC=g[c][c]&1;

    if (A>0&&B>0){
        res = ((!AA&&!BB&&!CC)||(!AA&&BB))^res_x;
    } else
    if (A>0&&C<0){
        res = ((!AA&BB)&&(!AA&(-CC)))^res_x;
    }else
    if (A>0){
        res = ((!AA&BB))^res_x;
    } else
    res = (!AA)^res_x;
//    printf("%d %d %d %d %d %d = %d\n",A,B,C,AA,BB,CC,res);
    return res;
}
int main()
{
    scanf("%d",&n);
    rep(i,n)scanf("%s",s[i]);
    int ans=0;
    rep(i,n)
    {
        memset(g,0,sizeof(g));
        id.clear();
        int cnt=0;
        rep(j,n)
        {
            if(i==j)continue;
            int len=strlen(s[j]);
            char a=s[j][0],b=s[j][len-1];
            int x,y;
            if(id.count(a)>0)x=id[a];else id[a]=++cnt,x=cnt;
            if(id.count(b)>0)y=id[b];else id[b]=++cnt,y=cnt;
            g[x][y]++;
        }
        char a=s[i][strlen(s[i])-1];
        int st;
        if(id.count(a)>0)st=id[a];else id[a]=++cnt,st=cnt;
        assert(cnt<=3);
//        printf("No %s\n",s[i]);
        if(check(cnt,st,g))ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3856kb

input:

3
attic
climb
alpha

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3944kb

input:

22
agora
alpha
antic
aorta
apnea
arena
aroma
attic
basic
blurb
china
circa
civic
climb
cobra
cocoa
comic
comma
conic
crumb
cubic
cynic

output:

6

result:

ok single line: '6'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3820kb

input:

3
ccabaabbba
acbbbacccb
ccccccacba

output:

1

result:

ok single line: '1'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3840kb

input:

11
mraa
myga
vtwm
mala
vvgm
atvv
vusm
mznv
avea
atfv
amgv

output:

4

result:

wrong answer 1st lines differ - expected: '7', found: '4'