Submission #2500578
Source Code Expand
#include<bits/stdc++.h> #define LL long long using namespace std; const int maxn = 5050; string s; int k, cnt[26]; set<string> Set; string ans[maxn]; vector<int> pos, t; int main() { cin >> s >> k; int n = s.size(); if(n < 50) { for(int i = 0; i < n; i ++) { for(int j = 1; j <= n - i; j ++) { if(Set.size() <= k) Set.insert(s.substr(i, j)); if(Set.size() > k) { auto it = Set.end(); it --; Set.erase(it); } } } cout << *(Set.rbegin()); } else { int mn = 1e9; for(int i = 0; i < n; i ++) cnt[s[i] - 'a'] ++; for(int i = 0; i < 26; i ++) { if(!cnt[i]) continue; Set.clear(); bool flag = false; for(int j = 0; j < n; j ++) { if(s[j] - 'a' == i) { for(int len = 1; len <= n - j; len ++) { Set.insert(s.substr(j, len)); if(Set.size() >= k) { flag = true; goto finish; } } } } finish: if(!flag) { k -= Set.size(); } else { mn = i; break; } } for(int i = 0; i < n; i ++) if(s[i] - 'a' == mn) pos.push_back(i); bool flag = false; for(int i = 1; i <= k; i ++) { if(pos.size() == 1) { for(int j = pos[0] - i + 1; j <= pos[0] - i + k; j ++) cout << s[j]; flag = true; break; } else { t.clear(); int mn = 1e9; for(int j = 0; j < pos.size(); j ++) if(pos[j] + 1 < n) mn = min(mn, s[pos[j] + 1] - 'a'); for(int j = 0; j < pos.size(); j ++) if(pos[j] + 1 < n && mn == s[pos[j] + 1] - 'a') t.push_back(pos[j] + 1); pos.clear(); for(int j = 0; j < t.size(); j ++) pos.push_back(t[j]); } } if(!flag) { for(int j = pos[0] - k + 1; j <= pos[0] - k + k; j ++) cout << s[j]; } } return 0; }
Submission Info
Submission Time | |
---|---|
Task | C - K-th Substring |
User | euLnaKt |
Language | C++14 (GCC 5.4.1) |
Score | 300 |
Code Size | 2579 Byte |
Status | AC |
Exec Time | 2 ms |
Memory | 384 KB |
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 | 2 ms | 384 KB |
2_012.txt | AC | 2 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 |