# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
633353 |
2022-08-22T07:39:18 Z |
codr0 |
Dabbeh (INOI20_dabbeh) |
C++14 |
|
2000 ms |
1048576 KB |
// Code by Parsa Eslami
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define bit(i,j) ((j>>i)&1)
#define F first
#define S second
#define dmid int mid=(r+l)/2
#define lc 2*id
#define rc 2*id+1
#define err(x) cerr<<#x<<"="<<x<<'\n'
#define pb push_back
#define SZ(x) (int)x.size()
#define all(x) x.begin(),x.end()
using namespace std;
int lcp(string a,string b){
FOR(j,0,min(SZ(a),SZ(b))-1) if(a[j]!=b[j]) return j;
return min(SZ(a),SZ(b));
}
int32_t main(){
iostream::sync_with_stdio(0); cin.tie(0);
int n,m; cin>>n>>m;
string x[n];
FOR(i,0,n-1) cin>>x[i];
string s; cin>>s;
int N=SZ(s);
string S[N];
S[N-1]=s[N-1];
FORR(i,N-2,0) S[i]=s[i]+S[i+1];
int dp[N][N];
FOR(i,0,N-1) FOR(j,0,N-1) dp[i][j]=1e9;
FORR(l,N-1,0) FOR(r,l,N-1){
int mx=0;
FOR(i,0,n-1) maxm(mx,lcp(x[i],S[l]));
if(mx+l>r) dp[l][r]=1;
else{
FOR(j,l+1,mx+l) minm(dp[l][r],dp[j][r]+1);
}
}
while(m--){
int l,r; cin>>l>>r;
r--;
if(dp[l][r]>N) dp[l][r]=-1;
cout<<dp[l][r]<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1491 ms |
1704 KB |
Output is correct |
3 |
Execution timed out |
2096 ms |
1108 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
401 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1491 ms |
1704 KB |
Output is correct |
3 |
Execution timed out |
2096 ms |
1108 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |