제출 #711818

#제출 시각아이디문제언어결과실행 시간메모리
711818Karpin세 명의 친구들 (BOI14_friends)C++14
100 / 100
28 ms7412 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define vt vector #define ar array void solve(){ int n; cin >> n; string u; cin >> u; int numOfEachChar[30]; for (int i = 0; i < 30; i++){ numOfEachChar[i] = 0; } for (int i = 0; i < n; i++){ numOfEachChar[u[i] - 'A']++; } if (n % 2 == 0){ cout << "NOT POSSIBLE" << endl; return; } bool torf = false; int neededChar = -1; for (int i = 0; i < 26; i++){ if (numOfEachChar[i] % 2 == 1){ if (torf){ cout << "NOT POSSIBLE" << endl; return; } torf = true; neededChar = i; } } if (!torf){ cout << "NOT POSSIBLE" << endl; return; } // vt<int> poses; // for (int i = 0; i < n; i++){ // if (u[i] - 'A' == neededChar) poses.push_back(i); // } string res = ""; int plusOne = 0; for (int i = 0; i <= n / 2; i++){ if (i == n / 2 && plusOne == 0) break; if (u[i] != u[i + n / 2 + 1 - plusOne]) { if (plusOne) { res = ""; break; } plusOne++; }else{ res += u[i]; } } plusOne = 0; string res2 = ""; for (int i = 0; i <= n / 2; i++){ if (i == n / 2 && plusOne == 0) break; if (u[i - plusOne] != u[i + n / 2]){ if (plusOne){ res2 = ""; break; } plusOne++; }else{ res2 += u[i + n / 2]; } } if (res == "" && res2 == "") cout << "NOT POSSIBLE" << endl; else if (res != "" && res2 == "") cout << res << endl; else if (res == "" && res2 != "") cout << res2 << endl; else if (res == res2) cout << res << endl; else cout << "NOT UNIQUE" << endl; } int main(){ ios::sync_with_stdio(0); cin.tie(0); int testcases = 1; // cin >> testcases; while(testcases--){ solve(); } return 0; }

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

friends.cpp: In function 'void solve()':
friends.cpp:37:9: warning: variable 'neededChar' set but not used [-Wunused-but-set-variable]
   37 |     int neededChar = -1;
      |         ^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...