QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#224869#6635. Strange KeyboardjbyCompile Error//C++202.8kb2023-10-23 16:18:112023-10-23 16:18:11

Judging History

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

  • [2023-10-23 16:18:11]
  • 评测
  • [2023-10-23 16:18:11]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define For(x, y, z) for(int x = (y); x <= (z); x++)
#define Rep(x, y, z) for(int x = (y); x >= (z); x--)
using namespace std;
const int MAXN = 1e6 + 5000 + 5;
const ll INF = 1e18;
char buf[1 << 12], *pp1 = buf, *pp2 = buf, nc;
inline char gc() {
    return (pp1 == pp2) && (pp2 = (pp1 = buf) + fread(buf, 1, 1 << 12, stdin), pp1 == pp2) ? EOF : *pp1++;
}
inline int read() {
    int x = 0, ny = 1;
    for(; nc = gc(), (nc < 48 || nc > 57) && nc != EOF; ) 
        if(nc == '-') ny = -1;
    if(nc < 0) return nc;
    x = nc ^ 48;
    for(; nc = gc(), (nc >= 48 && nc <= 57 && nc != EOF); )
        x = (x << 3) + (x << 1) + (nc ^ 48);
    return x * ny;
}
int n, k, d[MAXN];
char T[MAXN];
string S[MAXN];
set<int> len;
vector<int> G[MAXN];
int tot, ch[26][MAXN], rt;
ll Cost[MAXN];
inline int newNode() {
    int now = ++tot;
    For(c, 0, 25) ch[c][now] = 0;
    Cost[now] = INF;
    return now;
} 
inline void Init() {
    cin >> n >> k;
    len.clear();
    For(i, 1, n) {
        cin >> S[i];
        len.insert(S[i].length());
    }
}
inline void add(int x, int y) {
    G[x].pb(y);
}
inline void Calc() {
    int Max = k + *len.rbegin();
    For(i, 0, Max) G[i].clear();
    For(i, k, Max) add(i - k, i);
    For(i, 1, k - 1) for(auto o : len) add(i + o, i);
    For(i, 0, Max) d[i] = -1;
    queue<int> q; q.push(0), d[0] = 0;
    while(!q.empty()) {
        int x = q.front(); q.pop();
        for(auto y : G[x]) if(d[y] == - 1) 
            q.push(y), d[y] = d[x] + 1;
    }
    
}
inline void Build() {
    tot = 0, rt = newNode();
    For(i, 1, n) {
        int len = S[i].length(), now = rt;
        For(j, 0, len - 1) {
            if(!ch[S[i][j] - 'a'][now]) 
                ch[S[i][j] - 'a'][now] = newNode();
            now = ch[S[i][j] - 'a'][now];
            Cost[now] = min(Cost[now], d[len - j - 1] + 1ll);
        }
    }
}
ll F[MAXN];
inline void GetAns() {
    cin >> T + 1;
    int len = strlen(T + 1);
    For(i, 0, len) F[i] = INF;
    F[0] = 0;
    For(i, 0, len - 1) {
        int now = rt;
        For(j, i + 1, len) {
            if(!ch[T[j] - 'a'][now]) break;
            now = ch[T[j] - 'a'][now], F[j] = min(F[j], F[i] + Cost[now]);
        }
    }
    if(F[len] < INF) cout << F[len] << '\n';
    else cout << -1 << '\n';
}
inline void Solve() {
    Init(), Calc(), Build(), GetAns();
}
int main() {
    // freopen(".in", "r", stdin);
    // freopen(".out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t; cin >> t;
    for( ; t--; ) Solve();
    return 0;
}

详细

answer.code: In function ‘void GetAns()’:
answer.code:83:9: error: no match for ‘operator>>’ (operand types are ‘std::istream’ {aka ‘std::basic_istream<char>’} and ‘char*’)
   83 |     cin >> T + 1;
      |     ~~~ ^~ ~~~~~
      |     |        |
      |     |        char*
      |     std::istream {aka std::basic_istream<char>}
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:1:
/usr/include/c++/11/istream:168:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ (near match)
  168 |       operator>>(bool& __n)
      |       ^~~~~~~~
/usr/include/c++/11/istream:168:7: note:   conversion of argument 1 would be ill-formed:
answer.code:83:14: error: cannot bind non-const lvalue reference of type ‘bool&’ to a value of type ‘char*’
   83 |     cin >> T + 1;
      |            ~~^~~
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:1:
/usr/include/c++/11/istream:172:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char; _Traits = std::char_traits<char>]’ (near match)
  172 |       operator>>(short& __n);
      |       ^~~~~~~~
/usr/include/c++/11/istream:172:7: note:   conversion of argument 1 would be ill-formed:
answer.code:83:14: error: invalid conversion from ‘char*’ to ‘short int’ [-fpermissive]
   83 |     cin >> T + 1;
      |            ~~^~~
      |              |
      |              char*
answer.code:83:14: error: cannot bind rvalue ‘(short int)(((char*)(& T)) + 1)’ to ‘short int&’
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:1:
/usr/include/c++/11/istream:175:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ (near match)
  175 |       operator>>(unsigned short& __n)
      |       ^~~~~~~~
/usr/include/c++/11/istream:175:7: note:   conversion of argument 1 would be ill-formed:
answer.code:83:14: error: invalid conversion from ‘char*’ to ‘short unsigned int’ [-fpermissive]
   83 |     cin >> T + 1;
      |            ~~^~~
      |              |
      |              char*
answer.code:83:14: error: cannot bind rvalue ‘(short unsigned int)(((char*)(& T)) + 1)’ to ‘short unsigned int&’
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:1:
/usr/include/c++/11/istream:179:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char; _Traits = std::char_traits<char>]’ (near match)
  179 |       operator>>(int& __n);
      |       ^~~~~~~~
/usr/include/c++/11/istream:179:7: note:   conversion of argument 1 would be ill-formed:
answer.code:83:14: error: invalid conversion from ‘char*’ to ‘int’ [-fpermissive]
   83 |     cin >> T + 1;
      |            ~~^~~
      |              |
      |              char*
answer.code:83:14: error: cannot bind rvalue ‘(int)(((char*)(& T)) + 1)’ to ‘int&’
In file included from /usr/include/c++/11/sstream:38,
                 from /usr/include/c++/11/complex:45,
                 from /usr/include/c++/11/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:54,
                 from answer.code:1:
/usr/include/c++/11/istream:182:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream<char>]’ (near match)
  182 |       operator>>(unsigned int& __n)
      |       ^~~~~~~~
/usr/include/c++/11/istream:182:7: note:   conversion of argument 1 would be ill-formed:
answer.code:83:14: error: invalid conversion from ‘char*’ to ‘unsigned int’ [-fpermissive]
   83 |     cin >> T + 1;
    ...