Submission #1112251

#TimeUsernameProblemLanguageResultExecution timeMemory
1112251lucascgarThree Friends (BOI14_friends)C++17
100 / 100
23 ms8364 KiB
#include <bits/stdc++.h> using namespace std; /* resposta ta na metade esquerda ou na metade direita */ typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef pair<long double, long double> pdd; const int MAXN = 2e6+11; int q[27]; // A = 0 bool check(string &c, string &o){ // cerr << c << ' ' << o << '\n'; bool s = 0; int j = 0; for (int i=0;i<c.size();i++){ char x = c[i]; if (o[j] == x){ j++; continue; } if (s) return 0; s=1, j++, i--; } return 1; } signed main(){ std::ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; string s; cin >> s; for (auto &x:s) q[x-'A']++; int qo = 0, tg; for (int i=0;i<26;i++) if (q[i]%2==1){ qo++, tg=i; } if (s.size()%2 == 0 || qo>1){ cout << "NOT POSSIBLE\n"; return 0; } set<string> fans; int sz = n/2; string st, o; for (int i=0;i<sz;i++){ st.push_back(s[i]); } for (int i=sz;i<n;i++) o.push_back(s[i]); if (check(st, o)) fans.insert(st); st.clear(); o.clear(); for (int i=0;i<=sz;i++) o.push_back(s[i]); for (int i=sz+1;i<n;i++) st.push_back(s[i]); if (check(st, o)) fans.insert(st); if (fans.empty()){ cout << "NOT POSSIBLE\n"; }else if (fans.size()>1){ cout << "NOT UNIQUE\n"; }else{ cout << *fans.begin() << '\n'; } return 0; }

Compilation message (stderr)

friends.cpp: In function 'bool check(std::string&, std::string&)':
friends.cpp:21:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int i=0;i<c.size();i++){
      |                  ~^~~~~~~~~
friends.cpp: In function 'int main()':
friends.cpp:44:17: warning: variable 'tg' set but not used [-Wunused-but-set-variable]
   44 |     int qo = 0, tg;
      |                 ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...