QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#136075 | #6635. Strange Keyboard | Delay_for_five_minutes | Compile Error | / | / | C++20 | 2.3kb | 2023-08-06 23:46:02 | 2023-08-06 23:46:03 |
Judging History
你现在查看的是最新测评结果
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-08-06 23:46:03]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-08-06 23:46:02]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n , k;
string s[1000005];
set<int> st;
vector<pair<int,int> > E[5005];
int dis[5005];
void dij()
{
priority_queue<pair<int,int> , vector<pair<int,int> > , greater<pair<int,int> > > pq;
for(int i = 0;i < k;i++) dis[i] = 1e9;
dis[0] = 0;
pq.push(pair<int,int>{0 , 0});
while(pq.size()) {
int u = pq.top().second ; pq.pop();
for(auto &[v , w] : E[u]) {
if(dis[u] + w < dis[v]) {
dis[v] =dis[u] + w;
pq.push(pair<int,int>{dis[v] , v});
}
}
}
return;
}
struct trie {
int mn;
int ch[26];
clr() {
memset(ch,0,sizeof(ch));
mn = 1e9;
}
}T[1000005];
int cnt ;
inline int get(int x)
{
return x/k + dis[x % k];
}
void ins(const string &s)
{
int u = 0;
for(int i = 0;i < s.size();i++) {
int t = s[i] - 'a';
if(!T[u].ch[t]) {
T[u].ch[t] = ++cnt ; T[cnt].clr();
}
u = T[u].ch[t];
T[u].mn = min(T[u].mn , get(s.size() - i - 1) + 1);
}
return;
}
ll dp[5005];
void solve()
{
cin >> n >> k; st.clear();cnt = 0; T[0].clr();
for(int i = 0;i < k;i++) E[i].clear();
for(int i = 1;i <= n;i++) {
cin >> s[i]; st.insert(s[i].size());
}
for(auto L : st) {
for(int i = 0;i < k;i++) { /// (u + L) mod k = i
int u = (i - L%k + k) % k;
E[i].push_back(pair<int,int>{u , (u + L) / k + 1}) ;
}
}
dij() ;
// for(int i = 0;i < k;i++) printf("dist %d %d\n",i,dis[i]);
for(int i = 1;i <= n;i++) {
ins(s[i]);
}
string t;cin >> t;
dp[0] = 0;
for(int i = 1;i <= t.size();i++) dp[i] = 1e18;
for(int i = 0;i < t.size();i++) {
int u = 0;
for(int j = i + 1;j <= t.size();j++) {
u = T[u].ch[t[j - 1] - 'a'] ;
if(!u) break;
dp[j] = min(dp[j] , dp[i] + T[u].mn);
}
}
if(dp[t.size()] > 1e17) cout << -1 << '\n';
else cout << dp[t.size()] << '\n';
}
int main()
{
// freopen("in.txt","r",stdin);
ios::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
int t;cin >> t;
while(t--) solve();
return 0;
}
Details
answer.code:29:5: error: ISO C++ forbids declaration of ‘clr’ with no type [-fpermissive] 29 | clr() { | ^~~ answer.code: In member function ‘int trie::clr()’: answer.code:32:5: warning: no return statement in function returning non-void [-Wreturn-type] 32 | } | ^