답안 #931120

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931120 2024-02-21T09:33:36 Z Bzslayed 세 명의 친구들 (BOI14_friends) C++17
0 / 100
16 ms 5120 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pff pair<float, float>
#define coutpair(p) cout << p.first << " " << p.second << "\n"

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

int main(){
    ios_base::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);

    int n; cin >> n;
    string s; cin >> s;
    unordered_map<char, int> m;

    if (s.length()%2==0){
        cout << "NOT POSSIBLE";
        return 0;
    }

    int cnt = 0, occur = 0;
    char nl = '2';
    string ans;

    for (int i=0; i<s.length(); i++) m[s[i]]++;
    for (auto it : m){
        if (it.second%2!=0 && it.second != nl){
            cnt++;
            nl = it.first;
            occur = m[it.first];
        }

        if (cnt > 1){
            cout << "NOT POSSIBLE";
            return 0;
        }
    }

    for (int i=0; i<s.length(); i++){
        if (s[i] == nl){
            if (m[s[i]] == 1) continue;
            else if (m[s[i]] > 1){
                ans += s[i];
                m[s[i]]--;
                continue;
            }
        }
        else ans += s[i];

        if (ans.length() == s.length()/2) break;
    }

    m[nl] = 0;
    string ans2;

    for (int i=n-1; i>=0; i--){
        if (s[i] == nl) m[s[i]]++;
        else ans2 += s[i];
        if (m[s[i]] == nl/2 || ans2.length() == s.length()/2) break;
    }

    reverse(ans2.begin(), ans2.end());
    //cout << ans << " " << ans2;

    if (s[0] == nl && s[s.length()-1] == nl) cout << "NOT UNIQUE";
    else if (ans == ans2) cout << ans;
    else cout << "NOT POSSIBLE";

    return 0;
}

Compilation message

friends.cpp: In function 'int main()':
friends.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for (int i=0; i<s.length(); i++) m[s[i]]++;
      |                   ~^~~~~~~~~~~
friends.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |     for (int i=0; i<s.length(); i++){
      |                   ~^~~~~~~~~~~
friends.cpp:34:18: warning: variable 'occur' set but not used [-Wunused-but-set-variable]
   34 |     int cnt = 0, occur = 0;
      |                  ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 460 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Incorrect 0 ms 348 KB Output isn't correct
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 5120 KB Output isn't correct
2 Halted 0 ms 0 KB -