Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- string s = "abcdabacdabcdef";
- //~ bool is_unique (string & t) {
- //~ set<char> st;
- //~ for (int i = 0; i < (int) t.size(); ++i) {
- //~ st.insert(t[i]);
- //~ }
- //~ return (int) t.size() == (int) st.size();
- //~ }
- bool f (int len) {
- for (int i = 0; i <= (int) s.size() - len; ++i) {
- //~ if (is_unique(s.substr(i,len))) {
- //~ return true;
- //~ }
- set<char> st;
- for (int j = i; j < i + len; ++j) {
- st.insert(s[j]);
- }
- if ((int) st.size() == len) {
- return true;
- }
- }
- return false;
- }
- int main () {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int l = 1,r = 256;
- int res = 1;
- while (l <= r) {
- int mid = (l + r) / 2;
- //~ cout << mid << "->";
- if (f(mid)) {
- res = mid;
- l = mid + 1;
- } else {
- r = mid - 1;
- }
- }
- cout << '\n';
- cout << res << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement