Submission #38049894
Source Code Expand
#include <bits/stdc++.h>
//#define st first
#define nd second
#define db double
#define re register
#define pb push_back
#define mk make_pair
#define int long long
#define ldb long double
#define pii pair<int, int>
#define ull unsigned long long
#define mst(a, b) memset(a, b, sizeof(a))
using namespace std;
const int N = 5e3 + 10, lim = 1e5, INF = 1e15;
inline int read()
{
int s = 0, w = 1;
char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') w *= -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
int n;
char s[N];
signed main()
{
n = read(), cin >> s + 1;
for(re int i = 1; i < n; i++){
for(re int j = 1; j <= n - i; j++){
if(s[j] == s[i + j]){
cout << j - 1 << "\n";
goto NEX;
}
}
cout << n - i << "\n";
NEX:;
}
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - Longest Uncommon Prefix |
| User | Booksnow |
| Language | C++ (GCC 9.2.1) |
| Score | 200 |
| Code Size | 899 Byte |
| Status | AC |
| Exec Time | 17 ms |
| Memory | 3580 KiB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:27:24: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
27 | n = read(), cin >> s + 1;
| ~~^~~
./Main.cpp:28:14: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
28 | for(re int i = 1; i < n; i++){
| ^
./Main.cpp:29:16: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
29 | for(re int j = 1; j <= n - i; j++){
| ^
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 200 / 200 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt |
| All | sample_01.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| sample_01.txt | AC | 8 ms | 3484 KiB |
| test_01.txt | AC | 3 ms | 3416 KiB |
| test_02.txt | AC | 2 ms | 3356 KiB |
| test_03.txt | AC | 3 ms | 3412 KiB |
| test_04.txt | AC | 2 ms | 3412 KiB |
| test_05.txt | AC | 3 ms | 3580 KiB |
| test_06.txt | AC | 2 ms | 3496 KiB |
| test_07.txt | AC | 2 ms | 3540 KiB |
| test_08.txt | AC | 5 ms | 3416 KiB |
| test_09.txt | AC | 6 ms | 3556 KiB |
| test_10.txt | AC | 17 ms | 3416 KiB |
| test_11.txt | AC | 15 ms | 3528 KiB |
| test_12.txt | AC | 3 ms | 3544 KiB |
| test_13.txt | AC | 3 ms | 3420 KiB |
| test_14.txt | AC | 5 ms | 3564 KiB |
| test_15.txt | AC | 3 ms | 3420 KiB |
| test_16.txt | AC | 5 ms | 3484 KiB |
| test_17.txt | AC | 3 ms | 3496 KiB |
| test_18.txt | AC | 3 ms | 3576 KiB |
| test_19.txt | AC | 4 ms | 3492 KiB |