Submission #554527

#TimeUsernameProblemLanguageResultExecution timeMemory
554527Joshua_AnderssonThree Friends (BOI14_friends)C++14
0 / 100
8 ms5240 KiB
#undef _GLIBCXX_DEBUG // disable run-time bound checking, etc #pragma GCC optimize("Ofast,inline") // Ofast = O3,fast-math,allow-store-data-races,no-protect-parens #pragma GCC optimize ("unroll-loops") #pragma GCC target("bmi,bmi2,lzcnt,popcnt") // bit manipulation #pragma GCC target("movbe") // byte swap #pragma GCC target("aes,pclmul,rdrnd") // encryption #pragma GCC target("avx,avx2,f16c,fma,sse3,ssse3,sse4.1,sse4.2") // SIMD #include <bits/stdc++.h> //#include <bits/extc++.h> using namespace std; #define enablell 0 #define ll long long #if enablell #define int ll #define inf 2e18 #define float double #else #define inf int(2e9) #endif #define vi vector<int> #define vvi vector<vi> #define vvvi vector<vvi> #define vvvvi vector<vvvi> #define vb vector<bool> #define vvb vector<vb> #define vvvb vector<vvb> #define p2 pair<int, int> #define vp2 vector<p2> #define vvp2 vector<vp2> #define vvvp2 vector<vvp2> #define p3 tuple<int,int,int> #define vp3 vector<p3> #define vvp3 vector<vp3> #define vvvp3 vector<vvp3> #define p4 tuple<int,int,int,int> #define vp4 vector<p4> #define read(a) cin >> a #define read2(a,b) cin >> a >> b #define read3(a,b,c) cin >> a >> b >> c #define write(a) cout << (a) << "\n" #define quit cout << endl; _Exit(0); #define dread(type, a) type a; cin >> a #define dread2(type, a, b) dread(type, a); dread(type, b) #define dread3(type, a, b, c) dread2(type, a, b); dread(type, c) #define dread4(type, a, b, c, d) dread3(type, a, b, c); dread(type, d) #define dread5(type, a, b, c, d, e) dread4(type, a, b, c, d); dread(type, e) #ifdef _DEBUG #define noop cout << ""; #define deb __debugbreak(); #define debassert(expr) if (!(expr)) deb; #define debif(expr) if(expr) deb; #else #define noop ; #define deb ; #define debassert(expr) ; #define debif(expr) ; #endif #define rep(i, high) for (int i = 0; i < high; i++) #define repp(i, low, high) for (int i = low; i < high; i++) #define repe(i, container) for (auto& i : container) #define per(i, high) for (int i = high-1; i >= 0; i--) #define perr(i, low, high) for (int i = high-1; i >= low; i--) #define readvector(type, name, size) vector<type> name(size); rep(i,size) {dread(type,temp); name[i]=temp;} #define all(a) begin(a),end(a) #define setcontains(set, x) (set.find(x) != set.end()) #define stringcontains(str, x) (str.find(x) != string::npos) #define within(a, b, c, d) (a >= 0 && a < b && c >= 0 && c < d) #define sz(container) ((int)container.size()) #define mp(a,b) (make_pair(a,b)) #define first(a) (*begin(a)) #define ceildiv(x,y) ((x + y - 1) / y) #define fract(a) (a-floor(a)) auto Start = chrono::high_resolution_clock::now(); #define elapsedmillis() (chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - Start).count()) #define rununtil(time) if (elapsedmillis() >= time) break; inline void fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } template <typename T, typename U> inline void operator+=(std::pair<T, U>& l, const std::pair<T, U>& r) { l = { l.first + r.first,l.second + r.second }; } template <typename T> inline int sgn(T val) { return (T(0) < val) - (val < T(0)); } template <typename Out> inline void split(const string& s, char delim, Out result) { istringstream iss(s); string item; while (getline(iss, item, delim)) { *result++ = item; } } inline vector<string> split(const string& s, char delim) { vector<string> elems; split(s, delim, back_inserter(elems)); return elems; } string test1(string& s, int n) { bool works = true; bool left = true; bool first = true; int p = (n - 1) / 2; int hi = p; for (int i = 0; i < hi; i++) { if (s[i] != s[i+p]) { if (!first) { return ""; } bool la = i+1<hi && s[i + 1] == s[i + p]; bool ra = (i + p + 1 < s.size() && s[i] == s[i + p + 1]); if (la&&ra) { first = false; p++; } else if (la) { left = false; p--; first = false; } else if (ra) { left = true; p++; first = false; } else { bool w = i + p + 1 < s.size() && s[i + 1] == s[i + p + 1]; if (w) { left = false; } else { return ""; } } } } if (left) { return s.substr(0, (n - 1) / 2); } else { return s.substr((n - 1) / 2+1); } } string test2(string& s, int n) { bool works = true; bool left = false; bool first = true; int p = (n - 1) / 2; for (int i = s.size()-1; i > (s.size()-1)/2; i--) { if (s[i] != s[i - p]) { if (!first) { return ""; } bool la = i-1 >= p && s[i - 1] == s[i - p]; bool ra = (i - p - 1 >= 0 && s[i] == s[i - p - 1]); if (la && ra) { first = false; p--; } else if (la) { left = true; p--; first = false; } else if (ra) { left = false; p++; first = false; } else { if (i==p) { left = false; continue; } bool w = (i - p - 1 >= 0 && s[i-1] == s[i - p - 1]); if (w) { left = true; } else { return ""; } } } } if (left) { return s.substr(0, (n - 1) / 2); } else { return s.substr((n - 1) / 2 + 1); } } int32_t main() { fast(); #if 0 ifstream cin("C:\\Users\\Matis\\source\\repos\\Comp prog\\x64\\Debug\\in.txt"); #endif dread(int, n); dread(string, u); if (n%2==0) { cout << "NOT POSSIBLE"; return 0; } int p = (n - 1) / 2; string a = test1(u, n); string b = test2(u, n); if (a!=""&&a == b) { cout << a; } else if (a!="" && b!="" && a != b) { cout << "NOT UNIQUE"; } else if (a!="") { cout << a; } else if (b!="") { cout << b; } else if (a == "" || b == "") { cout << "NOT POSSIBLE"; } else { cout << "NOT UNIQUE"; } quit; }

Compilation message (stderr)

friends.cpp: In function 'std::string test1(std::string&, int)':
friends.cpp:110:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |             bool ra = (i + p + 1 < s.size() && s[i] == s[i + p + 1]);
      |                        ~~~~~~~~~~^~~~~~~~~~
friends.cpp:130:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  130 |                 bool w = i + p + 1 < s.size() && s[i + 1] == s[i + p + 1];
      |                          ~~~~~~~~~~^~~~~~~~~~
friends.cpp:95:10: warning: unused variable 'works' [-Wunused-variable]
   95 |     bool works = true;
      |          ^~~~~
friends.cpp: In function 'std::string test2(std::string&, int)':
friends.cpp:162:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  162 |     for (int i = s.size()-1; i > (s.size()-1)/2; i--)
      |                              ~~^~~~~~~~~~~~~~~~
friends.cpp:157:10: warning: unused variable 'works' [-Wunused-variable]
  157 |     bool works = true;
      |          ^~~~~
friends.cpp: In function 'int32_t main()':
friends.cpp:237:9: warning: unused variable 'p' [-Wunused-variable]
  237 |     int p = (n - 1) / 2;
      |         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...