Submission #1067793

#TimeUsernameProblemLanguageResultExecution timeMemory
1067793ntnqSelling RNA Strands (JOI16_selling_rna)C++17
10 / 100
1563 ms37716 KiB
#include <bits/stdc++.h>
using namespace std;

string a[1000006], st1, st2;
int n, m;
long long ans;

bool check(string st, string s, string x)
{
    if (st.size()>x.size()) return false;
    if (s.size()>x.size()) return false;
    
    for (int i = 0; i<st.size(); i++)
        if (st[i]!=x[i]) return false;
    
    int i = s.size()-1;
    for (int j=x.size()-1; j>=0; j--)
    {
        if (s[i]!=x[j]) return false;
        i--;
        if (i==-1) return true;
    }
        
    return true;
    
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    cin >> n >> m;
    for (int i=1; i<=n; i++) cin >> a[i];
    sort (a+1, a+n+1);
    
    for (int i=1; i<=m; i++)
    {
        cin >> st1 >> st2;
        
        ans = 0LL;
        for (int j=1; j<=n; j++)
        {
            if (a[j][1] != st1[0] && a[j][a[j].size()-1] != st2[st2.size()-1]) continue;
            if (check(st1, st2, a[j])) ans++;
        }
            
        
        cout << ans << '\n';
    }
}

Compilation message (stderr)

selling_rna.cpp: In function 'bool check(std::string, std::string, std::string)':
selling_rna.cpp:13:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |     for (int i = 0; i<st.size(); i++)
      |                     ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...