QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#630537#6611. United in StormwindOkuchiriWA 8ms11940kbC++202.9kb2024-10-11 19:03:012024-10-11 19:03:01

Judging History

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

  • [2024-10-11 19:03:01]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:11940kb
  • [2024-10-11 19:03:01]
  • 提交

answer

#include<bits/stdc++.h>
#define ll int
#define mod 1000000007
using namespace std;
ll root=1,n,m,k;
vector<ll>ly[22];
vector<ll>ttp;
ll tot=1,son[2200006][2],sz[2200006][21][2],a[1100006],b[1100006],c[1100006],dep[2200006],ex[30],lg[1100006];
void work()
{
    ex[0]=1;
    for(ll i=1;i<30;i++)ex[i]=ex[i-1]<<1;
    for(ll i=1;i<=1100000;i++)
    {
        lg[i]=lg[i-1];
        if(i==ex[lg[i]+1])lg[i]++;
    }
    lg[0]=-1;
    cin>>n>>m>>k;
    ly[m+1].push_back(root);
    dep[root]=0;
    for(ll i=1;i<=n;i++)
    {
        string s;
        cin>>s;
        ll tmp[22];
        ll now=root;
        for(ll j=0;j<m;j++)
        {
            ll d;
            if(s[j]=='A')d=0;
            else d=1;
            if(son[now][d]==0)
            {
                tot++;
                son[now][d]=tot;
            }
            now=son[now][d];
            dep[now]=j+1;
            ly[m-j].push_back(now);
            for(ll p=dep[now]-1;p<m;p++)
            {
                if(s[p]=='A')
                {
                    sz[now][m-p][0]++;
                }
                else
                {
                    sz[now][m-p][1]++;
                }
            }
        }
    }
    for(ll i=1;i<=m+1;i++)
    {
        ttp.clear();
        sort(ly[i].begin(),ly[i].end());
        for(ll j=0;j<ly[i].size();j++)
        {
            if(j==0||ly[i][j]!=ly[i][j-1])
            {
                ttp.push_back(ly[i][j]);
            }
        }
        ly[i].clear();
        for(ll j=0;j<ttp.size();j++)
        {
            ly[i].push_back(ttp[j]);
        }
    }
    for(ll i=1;i<=m;i++)
    {
        ll nn[21],yy=0;
        memset(nn,0,sizeof(nn));
        for(ll j=0;j<ly[i+1].size();j++)
        {
            ll ls=son[ly[i+1][j]][0];
            ll rs=son[ly[i+1][j]][1];
            if(ls&&rs)
            {
                yy+=sz[ls][m+1-dep[ls]][0]*sz[rs][m+1-dep[rs]][1]+sz[ls][m+1-dep[ls]][1]*sz[rs][m+1-dep[rs]][0];
                for(ll p=i;p>=1;p--)
                {
                    nn[p]+=sz[ls][p][0]*sz[rs][p][1]+sz[ls][p][1]*sz[rs][p][0];
                }
//                cout<<i<<' '<<j<<':'<<yy<<' ';
//                for(ll p=i;p>=1;p--)cout<<nn[p]<<' ';
//                cout<<endl;
            }
        }
        for(ll j=0;j<ex[i-1];j++)
        {
            b[ex[i-1]+j]=b[j]+yy;
            b[j]=a[j]+nn[lg[j]+1];
//            cout<<ex[i-1]+j<<"<-"<<j<<' '<<b[j]<<'+'<<yy<<endl;
        }
        for(ll j=0;j<ex[i];j++)
        {
            a[j]=b[j];
//            cout<<i<<','<<j<<':'<<a[j]<<endl;
        }
    }
    ll answer=0;
    for(ll i=0;i<ex[m];i++)
    {
        if(a[i]>=k)
        {
//            cout<<"Answer:"<<i<<endl;
            answer++;
        }
    }
    cout<<answer;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll T=1;
    while(T--)
    {
        work();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 5ms
memory: 11940kb

input:

2 2 1
AA
BB

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 5ms
memory: 10620kb

input:

2 2 1
AA
AB

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 8ms
memory: 11368kb

input:

5000 10 12302135
AABAAAABBA
AAABAABBAB
BAABABAAAB
ABBAABBBBA
BAAAAABAAB
BABBAAAAAA
BABBABABAB
BBABBAAAAB
BABBABBBBA
AAAAAAABAA
BBBBBAABBA
BAABABBAAB
BABAAABAAA
AAAAABAABB
BBABAABABB
ABAABBABBA
BBBAAABABA
BAAABABBAB
ABAAAAABAA
AABBBBBBAA
ABBABBABBA
AABBBABBAB
BAABBAAABB
BAAABBBBBB
ABABBAABBB
BABBABBA...

output:

28

result:

wrong answer 1st numbers differ - expected: '300', found: '28'