Submission #1367052
Source Code Expand
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> typedef long long ll ; #define rep(i, a, b) for (int i = a; i <= b; ++ i) const int N = 1000005 ; using namespace std ; int n, h[26], f[N][26], r[N] ; char s[N], t[N] ; struct poi { int x, y ; } a[N] ; int main() { scanf("%d", &n) ; scanf("%s%s", s + 1, t + 1) ; bool flg = true ; rep(i, 1, n) if (s[i] != t[i]) flg = false ; if (flg) { printf("0\n") ; return 0 ; } rep(i, 0, 25) h[i] = 0 ; rep(i, 1, n) { h[s[i] - 'a'] = i ; rep(j, 0, 25) f[i][j] = h[j] ; } int las = n ; for (int i = n ; i; -- i) { las = min(las, i) ; int x = f[las][t[i] - 'a'] ; if (!x) { printf("-1\n") ; return 0 ; } r[x] = max(r[x], i) ; las = x ; } int tot = 0, ans = 0 ; rep(i, 1, n) if (r[i]) { ++ tot ; a[tot].x = i, a[tot].y = r[i] ; } a[tot + 1].x = n + 1 ; rep(i, 1, n) { int l = i, r = tot + 1, goal = a[i].y - i, ret = r ; for ( ; l <= r ; ) { int mid = (l + r) / 2 ; if (a[mid].x - mid >= goal) ret = mid, r = mid - 1 ; else l = mid + 1 ; } ans = max(ans, ret - i) ; } printf("%d\n", ans) ; return 0 ; }
Submission Info
Submission Time | |
---|---|
Task | F - Shik and Copying String |
User | mjy0724 |
Language | C++14 (GCC 5.4.1) |
Score | 1500 |
Code Size | 1432 Byte |
Status | AC |
Exec Time | 139 ms |
Memory | 115456 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:18:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n) ; ^ ./Main.cpp:19:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s%s", s + 1, t + 1) ; ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1500 / 1500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt, example2.txt, example3.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, 057.txt, 058.txt, example0.txt, example1.txt, example2.txt, example3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 2 ms | 4352 KB |
001.txt | AC | 2 ms | 6400 KB |
002.txt | AC | 2 ms | 6400 KB |
003.txt | AC | 2 ms | 6400 KB |
004.txt | AC | 2 ms | 6400 KB |
005.txt | AC | 2 ms | 6400 KB |
006.txt | AC | 2 ms | 6400 KB |
007.txt | AC | 2 ms | 6400 KB |
008.txt | AC | 2 ms | 6400 KB |
009.txt | AC | 2 ms | 6400 KB |
010.txt | AC | 2 ms | 6400 KB |
011.txt | AC | 2 ms | 6400 KB |
012.txt | AC | 2 ms | 6400 KB |
013.txt | AC | 2 ms | 6400 KB |
014.txt | AC | 2 ms | 6400 KB |
015.txt | AC | 2 ms | 6400 KB |
016.txt | AC | 2 ms | 6400 KB |
017.txt | AC | 2 ms | 6400 KB |
018.txt | AC | 2 ms | 6400 KB |
019.txt | AC | 2 ms | 6400 KB |
020.txt | AC | 2 ms | 6400 KB |
021.txt | AC | 2 ms | 6400 KB |
022.txt | AC | 2 ms | 6400 KB |
023.txt | AC | 2 ms | 6400 KB |
024.txt | AC | 2 ms | 6400 KB |
025.txt | AC | 7 ms | 4352 KB |
026.txt | AC | 105 ms | 115456 KB |
027.txt | AC | 82 ms | 113408 KB |
028.txt | AC | 106 ms | 115456 KB |
029.txt | AC | 106 ms | 115456 KB |
030.txt | AC | 100 ms | 115456 KB |
031.txt | AC | 100 ms | 115456 KB |
032.txt | AC | 97 ms | 115456 KB |
033.txt | AC | 96 ms | 115456 KB |
034.txt | AC | 91 ms | 115456 KB |
035.txt | AC | 89 ms | 115456 KB |
036.txt | AC | 84 ms | 113408 KB |
037.txt | AC | 82 ms | 113408 KB |
038.txt | AC | 78 ms | 113408 KB |
039.txt | AC | 75 ms | 113408 KB |
040.txt | AC | 102 ms | 115456 KB |
041.txt | AC | 105 ms | 115456 KB |
042.txt | AC | 111 ms | 115456 KB |
043.txt | AC | 120 ms | 115456 KB |
044.txt | AC | 138 ms | 115456 KB |
045.txt | AC | 139 ms | 115456 KB |
046.txt | AC | 139 ms | 115456 KB |
047.txt | AC | 139 ms | 115456 KB |
048.txt | AC | 133 ms | 115456 KB |
049.txt | AC | 130 ms | 115456 KB |
050.txt | AC | 65 ms | 109312 KB |
051.txt | AC | 66 ms | 109312 KB |
052.txt | AC | 60 ms | 109312 KB |
053.txt | AC | 110 ms | 113536 KB |
054.txt | AC | 112 ms | 113408 KB |
055.txt | AC | 113 ms | 113408 KB |
056.txt | AC | 111 ms | 113408 KB |
057.txt | AC | 110 ms | 113408 KB |
058.txt | AC | 109 ms | 113408 KB |
example0.txt | AC | 2 ms | 6400 KB |
example1.txt | AC | 2 ms | 4352 KB |
example2.txt | AC | 2 ms | 6400 KB |
example3.txt | AC | 2 ms | 6400 KB |