Submission #2495505
Source Code Expand
#include <fstream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <bitset>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <set>
#include <complex>
using namespace std;
const int SIZE = 1 << 10;
int pointer = SIZE;
char buffer[SIZE];
char Advance() {
if (pointer == SIZE) {
fread(buffer, 1, SIZE, stdin);
pointer = 0;
}
return buffer[pointer++];
}
int Read() {
int answer = 0;
char ch = Advance();
while (!isdigit(ch))
ch = Advance();
while (isdigit(ch)) {
answer = answer * 10 + ch - '0';
ch = Advance();
}
return answer;
}
const int MAXN = 5000;
const int MAXK = 5;
const int SIGMA = 26;
int k, n;
char s[1 + MAXN], t[1 + MAXK + 1];
bool Find(int m) {
if (m > n)
return false;
for (int i = 1; i + m - 1 <= n; i++) {
bool ok = true;
for (int j = i; j <= i + m - 1; j++)
if (s[j] != t[j - i + 1])
ok = false;
if (ok)
return true;
}
return false;
}
void Backtracking(int m) {
for (char ch = 'a'; ch <= 'z'; ch++) {
m++;
t[m] = ch;
if (Find(m)) {
k--;
if (!k) {
t[m + 1] = NULL;
printf("%s\n", t + 1);
exit(0);
}
Backtracking(m);
}
m--;
}
}
int main() {
//freopen("tema.in", "r", stdin);
//freopen("tema.out", "w", stdout);
scanf("%s%d", s + 1, &k);
n = strlen(s + 1);
Backtracking(0);
return 0;
}
Submission Info
Submission Time
2018-05-12 21:05:33+0900
Task
C - K-th Substring
User
fanache99
Language
C++14 (GCC 5.4.1)
Score
300
Code Size
1729 Byte
Status
AC
Exec Time
2 ms
Memory
128 KB
Compile Error
./Main.cpp: In function ‘void Backtracking(int)’:
./Main.cpp:71:26: warning: converting to non-pointer type ‘char’ from NULL [-Wconversion-null]
t[m + 1] = NULL;
^
./Main.cpp: In function ‘char Advance()’:
./Main.cpp:25:38: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
fread(buffer, 1, SIZE, stdin);
^
./Main.cpp: In function ‘int main()’:
./Main.cpp:84:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s%d", s + 1, &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
128 KB
0_001.txt
AC
1 ms
128 KB
0_002.txt
AC
1 ms
128 KB
1_003.txt
AC
1 ms
128 KB
1_004.txt
AC
1 ms
128 KB
1_005.txt
AC
1 ms
128 KB
1_006.txt
AC
1 ms
128 KB
1_007.txt
AC
1 ms
128 KB
1_008.txt
AC
1 ms
128 KB
1_009.txt
AC
1 ms
128 KB
1_010.txt
AC
1 ms
128 KB
2_011.txt
AC
2 ms
128 KB
2_012.txt
AC
2 ms
128 KB
2_013.txt
AC
1 ms
128 KB
2_014.txt
AC
1 ms
128 KB
2_015.txt
AC
1 ms
128 KB
2_016.txt
AC
1 ms
128 KB
2_017.txt
AC
1 ms
128 KB
2_018.txt
AC
1 ms
128 KB