30pts求调

P10836 『FLA - I』歌静河

turing_IK @ 2024-08-04 10:05:07

#include<bits/stdc++.h>
using namespace std;
string s="aabcdefghijklmnopqrstuvwxyz";
long long n,m,s1,s2;
char a[1000005],b[1000005];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        if(a[i]=='#')
            s1++;
    }
    for(int i=1;i<=n;i++)
    {
        cin>>b[i];
        if(b[i]=='#')
            s2++;
    }
    if(s1==0&&s2<=26)   
    {
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(b[j]=='#')
                {
                    b[j]=s[i];
                    break;
                }
            }
        }
        for(int j=1;j<=n;j++)   cout<<b[j];
    }   
    else if(s2==0)
    {
        for(int i=1;i<=m;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(a[j]=='#')
                {
                    a[j]=s[i];
                    break;
                }
            }
        }
        for(int j=1;j<=n;j++)   cout<<a[j];
    }
    return 0;
}

也没啥不对呀

然后就


by Ahws_rwhy @ 2024-08-04 10:13:26

@tlsonghangtong 你觉得 O(nm) 的时间复杂度能过这题吗


by turing_IK @ 2024-08-04 16:28:30

@rwhy 哦!!!!


by turing_IK @ 2024-08-04 16:28:58

@rwhy 还是不懂


by Ahws_rwhy @ 2024-08-04 16:29:53

@tlsonghangtong 其实不用枚举 m ,时间复杂度 O(N)


by turing_IK @ 2024-08-04 16:30:40

知道了


|