Submission #1112220

#TimeUsernameProblemLanguageResultExecution timeMemory
1112220lucascgarThree Friends (BOI14_friends)C++17
35 / 100
1072 ms6412 KiB
#include <bits/stdc++.h> using namespace std; /* */ 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 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; } vector<int> fans; int sz = n/2; // meio for (int i=0;i<n;i++){ if ((i>0 && s[i] == s[i-1]) || s[i]-'A' !=tg){ continue; } string a, b; int j = 0; while (a.size()<sz){ if (j!=i) a.push_back(s[j]); j++; } while (b.size()<sz){ if (j!=i) b.push_back(s[j]); j++; } if (a==b) fans.push_back(i); } if (fans.empty()){ cout << "NOT POSSIBLE\n"; }else if (fans.size()>1){ cout << "NOT UNIQUE\n"; // for (auto &x:fans) cerr << x << '\n'; } else{ int x = fans.back(), q=0, j=0; while (q<sz){ if (j!=x){ cout << s[j]; q++; } j++; } cout << '\n'; } return 0; }

Compilation message (stderr)

friends.cpp: In function 'int main()':
friends.cpp:46:24: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   46 |         while (a.size()<sz){
      |                ~~~~~~~~^~~
friends.cpp:50:24: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |         while (b.size()<sz){
      |                ~~~~~~~~^~~
friends.cpp:41:37: warning: 'tg' may be used uninitialized in this function [-Wmaybe-uninitialized]
   41 |         if ((i>0 && s[i] == s[i-1]) || s[i]-'A' !=tg){
      |             ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...