Submission #105809

#TimeUsernameProblemLanguageResultExecution timeMemory
105809xiaowuc1Three Friends (BOI14_friends)C++14
100 / 100
24 ms7452 KiB
#include <algorithm> #include <cassert> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<int, pii> pipii; typedef vector<vector<ll>> matrix; bool can(string a, string b) { int aIdx = 0; for(int i = 0; i < b.size() && aIdx < a.size(); i++) { if(b[i] == a[aIdx]) aIdx++; } return aIdx == a.size(); } void solve() { int n; string s; cin >> n >> s; if(n%2==0) { cout << "NOT POSSIBLE\n"; return; } n /= 2; set<string> ret; if(can(s.substr(0, n), s.substr(n))) { ret.insert(s.substr(0, n)); } if(can(s.substr(n+1), s.substr(0, n+1))) { ret.insert(s.substr(n+1)); } if(ret.size() > 1) cout << "NOT UNIQUE\n"; else if(ret.empty()) cout << "NOT POSSIBLE\n"; else cout << *ret.begin() << "\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); /* int t; cin >> t; for(int i = 1; i <= t; i++) { cout << "Case #" << i << ": "; solve(); } */ solve(); }

Compilation message (stderr)

friends.cpp: In function 'bool can(std::__cxx11::string, std::__cxx11::string)':
friends.cpp:21:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < b.size() && aIdx < a.size(); i++) {
                 ~~^~~~~~~~~~
friends.cpp:21:38: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < b.size() && aIdx < a.size(); i++) {
                                 ~~~~~^~~~~~~~~~
friends.cpp:24:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  return aIdx == a.size();
         ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...