Submission #1708216
Source Code Expand
#include<bits/stdc++.h> using namespace std; int nr, N, M, leftEnd[500009], rightEnd[500009], t[500009], first[500009][26]; char s[500009]; vector < int > v[500009]; void dfs (int nod) { leftEnd[nod] = ++nr; for (auto it : v[nod]) dfs (it); rightEnd[nod] = nr; } bool isAncestor (int up, int down) { return (leftEnd[up] <= leftEnd[down] && leftEnd[down] <= rightEnd[up]); } int main () { //freopen ("input", "r", stdin); //freopen ("output", "w", stdout); scanf ("%s", s + 1), N = strlen (s + 1); for (int i=1; i<=N; i++) s[i] -= 'a'; for (int i=N; i>=1; i--) { int c = s[i]; t[i] = -1, first[i][s[i]] = i; for (int j=i + 1; j<=N; j++) { if (s[j] == c) { if (c == 25) { t[i] = j + 1; break; } c ++, first[i][c] = j; } else { j = first[j][c]; if (j <= 0) break; if (c == 25) { t[i] = j + 1; break; } c ++, first[i][c] = j; } } if (t[i] != -1) { for (int j=0; j<26; j++) if (first[i][j] <= 0) first[i][j] = first[t[i]][j]; } } for (int i=1; i<=N; i++) if (t[i] != -1) v[t[i]].push_back (i); for (int i=1; i<=N + 1; i++) if (t[i] == -1 || i == N + 1) dfs (i); scanf ("%d", &M); while (M --) { int x, y; scanf ("%d %d", &x, &y); if (isAncestor (y + 1, x)) printf ("Yes\n"); else printf ("No\n"); } return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - Robot and String |
User | geniucos |
Language | C++14 (GCC 5.4.1) |
Score | 1300 |
Code Size | 1659 Byte |
Status | AC |
Exec Time | 140 ms |
Memory | 92928 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:27:40: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf ("%s", s + 1), N = strlen (s + 1); ^ ./Main.cpp:70:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf ("%d", &M); ^ ./Main.cpp:74:28: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf ("%d %d", &x, &y); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1300 / 1300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt, 1_47.txt, 1_48.txt, 1_49.txt, 1_50.txt, 1_51.txt, 1_52.txt, 1_53.txt, 1_54.txt, 1_55.txt, 1_56.txt, 1_57.txt, 1_58.txt, 1_59.txt, 1_60.txt, 1_61.txt, 1_62.txt, 1_63.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 8 ms | 18688 KB |
0_01.txt | AC | 8 ms | 18688 KB |
0_02.txt | AC | 8 ms | 18688 KB |
1_00.txt | AC | 24 ms | 18944 KB |
1_01.txt | AC | 24 ms | 18944 KB |
1_02.txt | AC | 100 ms | 69376 KB |
1_03.txt | AC | 98 ms | 69376 KB |
1_04.txt | AC | 119 ms | 76928 KB |
1_05.txt | AC | 127 ms | 81024 KB |
1_06.txt | AC | 115 ms | 88960 KB |
1_07.txt | AC | 104 ms | 92928 KB |
1_08.txt | AC | 77 ms | 73472 KB |
1_09.txt | AC | 79 ms | 73472 KB |
1_10.txt | AC | 77 ms | 73472 KB |
1_11.txt | AC | 76 ms | 73600 KB |
1_12.txt | AC | 78 ms | 73472 KB |
1_13.txt | AC | 82 ms | 73984 KB |
1_14.txt | AC | 81 ms | 74240 KB |
1_15.txt | AC | 81 ms | 74240 KB |
1_16.txt | AC | 82 ms | 74496 KB |
1_17.txt | AC | 87 ms | 75136 KB |
1_18.txt | AC | 100 ms | 75776 KB |
1_19.txt | AC | 97 ms | 76032 KB |
1_20.txt | AC | 99 ms | 76160 KB |
1_21.txt | AC | 103 ms | 76672 KB |
1_22.txt | AC | 114 ms | 77824 KB |
1_23.txt | AC | 121 ms | 78720 KB |
1_24.txt | AC | 133 ms | 80128 KB |
1_25.txt | AC | 137 ms | 81408 KB |
1_26.txt | AC | 140 ms | 82688 KB |
1_27.txt | AC | 136 ms | 83840 KB |
1_28.txt | AC | 126 ms | 84736 KB |
1_29.txt | AC | 118 ms | 85376 KB |
1_30.txt | AC | 109 ms | 86016 KB |
1_31.txt | AC | 108 ms | 87040 KB |
1_32.txt | AC | 104 ms | 88960 KB |
1_33.txt | AC | 53 ms | 69504 KB |
1_34.txt | AC | 75 ms | 75008 KB |
1_35.txt | AC | 93 ms | 80384 KB |
1_36.txt | AC | 100 ms | 82304 KB |
1_37.txt | AC | 105 ms | 83840 KB |
1_38.txt | AC | 106 ms | 84608 KB |
1_39.txt | AC | 104 ms | 84864 KB |
1_40.txt | AC | 101 ms | 84864 KB |
1_41.txt | AC | 101 ms | 85376 KB |
1_42.txt | AC | 100 ms | 84992 KB |
1_43.txt | AC | 102 ms | 85760 KB |
1_44.txt | AC | 101 ms | 85632 KB |
1_45.txt | AC | 103 ms | 85760 KB |
1_46.txt | AC | 101 ms | 86272 KB |
1_47.txt | AC | 101 ms | 86528 KB |
1_48.txt | AC | 101 ms | 88064 KB |
1_49.txt | AC | 108 ms | 73216 KB |
1_50.txt | AC | 99 ms | 81152 KB |
1_51.txt | AC | 89 ms | 71552 KB |
1_52.txt | AC | 99 ms | 79232 KB |
1_53.txt | AC | 74 ms | 69504 KB |
1_54.txt | AC | 109 ms | 84864 KB |
1_55.txt | AC | 101 ms | 75520 KB |
1_56.txt | AC | 113 ms | 82944 KB |
1_57.txt | AC | 83 ms | 73216 KB |
1_58.txt | AC | 93 ms | 83200 KB |
1_59.txt | AC | 107 ms | 91008 KB |
1_60.txt | AC | 79 ms | 81152 KB |
1_61.txt | AC | 93 ms | 81280 KB |
1_62.txt | AC | 66 ms | 71552 KB |
1_63.txt | AC | 78 ms | 79360 KB |