제출 #711346

#제출 시각아이디문제언어결과실행 시간메모리
711346PoonYaPat세 명의 친구들 (BOI14_friends)C++14
0 / 100
17 ms5488 KiB
#include <bits/stdc++.h> using namespace std; string s,ans; int st,ed; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; cin>>s; if (s.size()%2==0) { cout<<"NOT POSSIBLE"; return 0; } //consider insert letter in the middle bool ok=true; for (int i=0; i<s.size()/2; ++i) { if (s[i]!=s[i+s.size()/2+1]) ok=false; } if (ok) { for (int i=0; i<s.size()/2; ++i) ans+=s[i]; } //consider insert letter on the left string for (int i=0; i<=s.size()/2; ++i) { if (s[i]!=s[i+s.size()/2+1] || i==s.size()/2) { ed=i; break; } } for (int i=s.size()/2; i>=0; --i) { if (s[i]!=s[i+s.size()/2] || i==0) { st=i; break; } } if (st<ed) { cout<<"NOT UNIQUE"; return 0; } else if (st==ed) { if (ans.size()==0) { int k=0,idx=0; while (k<s.size()/2) { if (st!=idx) ans+=s[idx], ++k; ++idx; } } else { bool check=true; int k=0,idx=0; while (k<s.size()/2) { if (st!=idx){ if (ans[k]!=s[idx]) { cout<<"NOT UNIQUE"; return 0; } else ++k; } ++idx; } } } //consider insert letter on the right string for (int i=s.size()/2; i<s.size(); ++i) { if (s[i]!=s[i-s.size()/2] || i==s.size()-1) { ed=i; break; } } for (int i=s.size()-1; i>=s.size()/2; --i) { if (s[i]!=s[i-s.size()/2-1] || i==s.size()/2) { st=i; break; } } if (st<ed) { cout<<"NOT UNIQUE"; return 0; } else if (st==ed) { if (ans.size()==0) { int k=0,idx=0; while (k<s.size()/2) { if (st!=idx) ans+=s[idx], ++k; ++idx; } } else { bool check=true; int k=0,idx=0; while (k<s.size()/2) { if (st!=idx){ if (ans[k]!=s[idx]) { cout<<"NOT UNIQUE"; return 0; } else ++k; } ++idx; } } } if (ans.size()==0) cout<<"NOT POSSIBLE"; else cout<<ans; }

컴파일 시 표준 에러 (stderr) 메시지

friends.cpp: In function 'int main()':
friends.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |     for (int i=0; i<s.size()/2; ++i) {
      |                   ~^~~~~~~~~~~
friends.cpp:23:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |         for (int i=0; i<s.size()/2; ++i) ans+=s[i];
      |                       ~^~~~~~~~~~~
friends.cpp:27:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int i=0; i<=s.size()/2; ++i) {
      |                   ~^~~~~~~~~~~~
friends.cpp:28:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         if (s[i]!=s[i+s.size()/2+1] || i==s.size()/2) {
      |                                        ~^~~~~~~~~~~~
friends.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |             while (k<s.size()/2) {
      |                    ~^~~~~~~~~~~
friends.cpp:52:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |             while (k<s.size()/2) {
      |                    ~^~~~~~~~~~~
friends.cpp:50:18: warning: unused variable 'check' [-Wunused-variable]
   50 |             bool check=true;
      |                  ^~~~~
friends.cpp:65:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |     for (int i=s.size()/2; i<s.size(); ++i) {
      |                            ~^~~~~~~~~
friends.cpp:66:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         if (s[i]!=s[i-s.size()/2] || i==s.size()-1) {
      |                                      ~^~~~~~~~~~~~
friends.cpp:71:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for (int i=s.size()-1; i>=s.size()/2; --i) {
      |                            ~^~~~~~~~~~~~
friends.cpp:72:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         if (s[i]!=s[i-s.size()/2-1] || i==s.size()/2) {
      |                                        ~^~~~~~~~~~~~
friends.cpp:83:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |             while (k<s.size()/2) {
      |                    ~^~~~~~~~~~~
friends.cpp:90:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |             while (k<s.size()/2) {
      |                    ~^~~~~~~~~~~
friends.cpp:88:18: warning: unused variable 'check' [-Wunused-variable]
   88 |             bool check=true;
      |                  ^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...