Submission #1001533

#TimeUsernameProblemLanguageResultExecution timeMemory
1001533vjudge1Dabbeh (INOI20_dabbeh)C++17
25 / 100
229 ms135752 KiB
#include <bits/stdc++.h> //#define int ll #define MAX 1000001 #define INF INT_MAX #define MOD 1000000007 #define mp make_pair #define mt make_tuple #define pb push_back #define ins insert #define ff first #define ss second #define all(a) a.begin(),a.end() #define lb(a,b) lower_bound(all(a),b) #define ub(a,b) upper_bound(all(a),b) #define sortv(a) sort(all(a)) #define outputar(a,b){\ for(int i=0;i<b;i++){\ cout << a[i] << " ";\ }\ cout << endl;\ } #define outputvec(a){\ for(auto x:a){\ cout << (int)x << " ";\ }\ cout << endl;\ } #define reset(a,n,v){\ for(int i=0;i<n;i++){\ a[i]=v;\ }\ } using namespace std; typedef long long ll; typedef unsigned long long ull; typedef tuple<ll,ll,ll> tll; typedef pair<ll,ll> pll; typedef pair<int,int> pii; typedef double db; typedef long double ldb; inline void USACO(string filename){ freopen((filename+".in").c_str(),"r",stdin); freopen((filename+".out").c_str(),"w",stdout); } int n,q,t=1,m,k,x,y,z,x2,y2,z2,a[MAX],b[MAX],d[MAX]; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); string s[MAX],str[MAX]; //int e[1001][1001]; string s1,s2,s3; const int mod = 998244353; int dx[4]={0,1,0,-1}; int dy[4]={1,0,-1,0}; int cost[501][501],can[501][501]; void solve(){ cin >> n >> q; for(int i=0;i<n;i++){ cin >> s[i]; } cin >> s1; m=(int)s1.size(); for(int i=0;i<m;i++){ for(int j=0;j<n;j++){ k=(int)s[j].size(); for(z=0;z<k;z++){ if(s[j][z]!=s1[i+z]){ break; } can[i][i+z]=1; } } } for(int i=0;i<m;i++){ for(int j=0;j<m;j++){ cost[i][j]=INF; } } for(int i=0;i<m;i++){ for(int j=i;j<m;j++){ if(can[i][j]){ cost[i][j]=1; if(i-1>=0){ for(int z=0;z<=i-1;z++){ if(cost[z][i-1]!=INF){ cost[z][j]=min(cost[z][j],cost[z][i-1]+1); } } } } } } for(int i=0;i<q;i++){ cin >> x >> y; if(cost[x][y-1]==INF){ cout << -1 << "\n"; } else{ cout << cost[x][y-1] << "\n"; } } } signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen("input13.txt","r",stdin); //cin >> t; ll cnt1=1; while(t--){ solve(); cnt1++; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...