Submission #1697380
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; typedef pair<double,int>Q; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define mod 1000000007 #define fi first #define sc second #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) char str[500005]; int q; int dp[500005][27]; int go[500005][21]; int main(){ scanf("%s%d",&str,&q); int n = strlen(str); rep(i,500005) rep(j,27) dp[i][j] = INF; for(int i=0;i<n;i++){ dp[i][str[i]-'a'] = i; } while(1){ bool upd = 0; for(int j=1;j<=26;j++){ for(int i=0;i<n;i++){ if(dp[i][j-1] < n && dp[dp[i][j-1]+1][j-1] < n && dp[i][j] > dp[dp[i][j-1]+1][j-1]){ dp[i][j] = dp[dp[i][j-1]+1][j-1]; upd = 1; } if(dp[i][26] < n && dp[dp[i][26]+1][j] < n && dp[i][j] > dp[dp[i][26]+1][j]){ dp[i][j] = dp[dp[i][26]+1][j]; upd = 1; } } } if(!upd) break; } for(int i=0;i<str.size();i++){ go[i][0] = dp[i][26]+1; //cout<<i<<" "<<go[i][0]<<endl; } go[n][0] = n; for(int j=0;j<19;j++){ for(int i=0;i<=n;i++){ if(go[i][j] >= n) go[i][j+1] = INF; else go[i][j+1] = go[go[i][j]][j]; } } //cout<<go[0][1]<<endl; rep(i,q){ int x,y; scanf("%d%d",&x,&y); x--; for(int i=19;i>=0;i--){ if(go[x][i] <= y) x = go[x][i]; } // cout<<x<<" "<<y<<endl; puts(x==y?"Yes":"No"); } }
Submission Info
Submission Time | |
---|---|
Task | C - Robot and String |
User | IH19980412 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1738 Byte |
Status | CE |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:27:22: warning: format ‘%s’ expects argument of type ‘char*’, but argument 2 has type ‘char (*)[500005]’ [-Wformat=] scanf("%s%d",&str,&q); int n = strlen(str); ^ ./Main.cpp:48:20: error: request for member ‘size’ in ‘str’, which is of non-class type ‘char [500005]’ for(int i=0;i<str.size();i++){ ^ ./Main.cpp:27:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s%d",&str,&q); int n = strlen(str); ^ ./Main.cpp:61:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] int x,y; scanf("%d%d",&x,&y); x--; ^