제출 #656211

#제출 시각아이디문제언어결과실행 시간메모리
656211600Mihnea세 명의 친구들 (BOI14_friends)C++17
100 / 100
13 ms13060 KiB
bool home = 0;
bool verbose = 1;

#include <bits/stdc++.h>

using namespace std;

int main() {

  if (!home) {
    verbose = 0;
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
  if (home) {
    verbose = 1;
    freopen ("___input___.txt", "r", stdin);
  }

  int n;
  cin >> n;
  if (n % 2 == 0) {
    cout << "NOT POSSIBLE\n";
    return 0;
  }
  string s;
  cin >> s;
  int half = (n - 1) / 2;
  string pref(s.begin(), s.begin() + half);
  string suf(s.end() - half, s.end());
  int cnt = 0;
  string goods;
  vector<string> trs;
  if (pref == suf) {
    trs = {pref + pref};
  } else {
    trs = {pref + pref, suf + suf};
  }
  for (auto &tr : trs) {

    int pcom = 0, scom = 0;
    while (pcom < n - 1 && tr[pcom] == s[pcom]) {
      pcom++;
    }
    while (scom < n - 1 && tr[(int) tr.size() - 1 - scom] == s[(int) s.size() - 1 - scom]) {
      scom++;
    }
    if (pcom >= n - 1 - scom) {
      cnt++;
      goods = tr;
    }
  }
  if (cnt == 0) {
    cout << "NOT POSSIBLE\n";
    return 0;
  }
  if (cnt == 2) {
    cout << "NOT UNIQUE\n";
    return 0;
  }
  goods.resize(half);
  cout << goods << "\n";
  return 0;
}

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

friends.cpp: In function 'int main()':
friends.cpp:18:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     freopen ("___input___.txt", "r", stdin);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...