답안 #1001621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1001621 2024-06-19T06:33:44 Z vjudge1 Dabbeh (INOI20_dabbeh) C++17
0 / 100
60 ms 15456 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define oo 1e9
const int MAX = 3e5 + 5;

int n, q;
string s;
string t[MAX];

int to[MAX][27][27];
void solve(){
    cin >> n >> q;
    for(int i = 1; i <= n; i++){
        cin >> t[i];
        t[i] = '{' + t[i];
    }
    cin >> s;
    s = '{' + s;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= t[i].size() - 1; j++){
            if(j >= s.size()) break;
            to[j - 1][t[i][j - 1] - 'a'][t[i][j] - 'a'] = 1;
            // cout << j - 1 << ' ' << t[i][j - 1] - 'a' << ' ' << t[i][j] - 'a' << '\n';
        }
    }
    while(q--){
        int l, r; cin >> l >> r;
        l++;
        int ans = 1;
        int i = 0, c = 26;
        while(true){
            if(l == r + 1) break;
            if(to[i][c][s[l] - 'a']){
                c = s[l] - 'a';
                i++;
                l++;
            }
            else if(!to[0][26][s[l] - 'a']){
                ans = -1;
                break;
            }
            else{
                ans++;
                i = 0, c = 26;
            }
        }
        cout << ans << '\n';
    }
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    while(t--){
        solve();
    }
}

Compilation message

Main.cpp: In function 'void solve()':
Main.cpp:25:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for(int j = 1; j <= t[i].size() - 1; j++){
      |                        ~~^~~~~~~~~~~~~~~~~~
Main.cpp:26:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |             if(j >= s.size()) break;
      |                ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10076 KB Output is correct
2 Incorrect 60 ms 15456 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 13588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10076 KB Output is correct
2 Incorrect 60 ms 15456 KB Output isn't correct
3 Halted 0 ms 0 KB -