Submission #2605798
Source Code Expand
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string.h>
using namespace std;
const int maxN = 50005;
char s[7][maxN], a[maxN];
int K, ed[7], idx[maxN];
int q[2][maxN], cnt[2], tot[maxN];
bool ok(int t, int idx, int k) {
for(int i = idx - 1; i >= idx - k; --i) {
if(i < 1) return 0;
if(a[i] != s[t][i + k - idx + 1]) return 0;
}
return a[idx] > s[t][k + 1];
}
/*
void print(int k) {
cout<<k<<"____________________"<<endl;
for(int i = 1; i <= ed[k]; ++i) printf("%c", s[k][i]);
cout << endl;
}*/
int main() {
scanf("%s", a + 1); scanf("%d", &K);
int len = strlen(a + 1);
char ch = 'z';
//for(int i = 1; i <= len; ++i) ch = min(ch, a[i]);
for(int i = 1; i <= len; ++i) q[0][++cnt[0]] = i;
//s[++ed] = ch;
int nw = 0;
for(int i = 1; i <= K; ++i) {
for(int j = 1; j <= ed[i]; ++j) s[i][j] = s[i - 1][j];
ch = 'z';
for(int j = 1; j <= cnt[nw]; ++j) ch = min(ch, a[q[nw][j]]);
for(int j = 1; j <= cnt[nw]; ++j) {
int t = q[nw][j];
if(ch == a[t]) {
if(t < len) q[nw ^ 1][++cnt[nw ^ 1]] = t + 1;
}
}
s[i][++ed[i]] = ch;
//print(i);
if(K == i) break;
if(cnt[nw ^ 1] == 0) {
for(int k = ed[i] - 1; k >= 0; --k) {
for(int t = 1; t <= len; ++t) if(ok(i, t, k)) q[nw ^ 1][++cnt[nw ^ 1]] = t;
if(cnt[nw ^ 1]) {
ed[i + 1] = k;
break;
}
}
} else ed[i + 1] = ed[i];
cnt[nw] = 0; nw ^= 1;
}
for(int i = 1; i <= ed[K]; ++i) {
printf("%c", s[K][i]);
}
printf("\n");
return 0;
}
Submission Info
Submission Time
2018-06-03 17:36:20+0900
Task
C - K-th Substring
User
amy1228
Language
C++14 (GCC 5.4.1)
Score
300
Code Size
1554 Byte
Status
AC
Exec Time
1 ms
Memory
384 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:28:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", a + 1); scanf("%d", &K);
^
./Main.cpp:28:37: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", a + 1); scanf("%d", &K);
^
Judge Result
Set Name
Sample
Subtask
All
Score / Max Score
0 / 0
200 / 200
100 / 100
Status
Set Name
Test Cases
Sample
0_000.txt, 0_001.txt, 0_002.txt
Subtask
0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt
All
0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 2_011.txt, 2_012.txt, 2_013.txt, 2_014.txt, 2_015.txt, 2_016.txt, 2_017.txt, 2_018.txt
Case Name
Status
Exec Time
Memory
0_000.txt
AC
1 ms
256 KB
0_001.txt
AC
1 ms
256 KB
0_002.txt
AC
1 ms
256 KB
1_003.txt
AC
1 ms
256 KB
1_004.txt
AC
1 ms
256 KB
1_005.txt
AC
1 ms
256 KB
1_006.txt
AC
1 ms
256 KB
1_007.txt
AC
1 ms
256 KB
1_008.txt
AC
1 ms
256 KB
1_009.txt
AC
1 ms
256 KB
1_010.txt
AC
1 ms
256 KB
2_011.txt
AC
1 ms
256 KB
2_012.txt
AC
1 ms
384 KB
2_013.txt
AC
1 ms
256 KB
2_014.txt
AC
1 ms
256 KB
2_015.txt
AC
1 ms
256 KB
2_016.txt
AC
1 ms
256 KB
2_017.txt
AC
1 ms
256 KB
2_018.txt
AC
1 ms
256 KB