Submission #19092644


Source Code Expand

Copy
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

using vi = vector<int>;
using vvi = vector<vi>;
using vpii = vector<pair<int,int>>;

void solve() {
    string S; cin >> S;
    map<char,int> mp;
    for(const auto &c: S) mp[c]++;

    int odds = 0; // 出現回数が奇数の種類数
    for(const auto &p: mp) if(p.second%2) odds++;

    // もし出現回数が0ならlen(S)が答え(並び替えで回文が出来るので)
    if(odds == 0) {
        cout << S.size() << endl;
        return;
    }

    const int MAX = 1e6;
    FOR(i,1,MAX) {
        if (odds * ((2 * i) - 1) > S.size()) {
            assert(i > 1);
            cout << (2 * (i-1)) - 1 << endl;
            return;
        }
    }
    assert(false);
}

int main() {
    solve();
    return 0;
}

Submission Info

Submission Time
Task B - 回文分割
User reud
Language C++ (GCC 9.2.1)
Score 100
Code Size 1281 Byte
Status AC
Exec Time 9 ms
Memory 3752 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:36:34: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   36 |         if (odds * ((2 * i) - 1) > S.size()) {
      |             ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 4
AC × 45
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt
Case Name Status Exec Time Memory
0_00.txt AC 6 ms 3608 KB
0_01.txt AC 2 ms 3608 KB
0_02.txt AC 2 ms 3484 KB
0_03.txt AC 2 ms 3540 KB
1_00.txt AC 2 ms 3536 KB
1_01.txt AC 2 ms 3532 KB
1_02.txt AC 2 ms 3408 KB
1_03.txt AC 3 ms 3584 KB
1_04.txt AC 9 ms 3612 KB
1_05.txt AC 8 ms 3668 KB
1_06.txt AC 5 ms 3716 KB
1_07.txt AC 9 ms 3664 KB
1_08.txt AC 2 ms 3524 KB
1_09.txt AC 3 ms 3552 KB
1_10.txt AC 2 ms 3408 KB
1_11.txt AC 4 ms 3620 KB
1_12.txt AC 2 ms 3472 KB
1_13.txt AC 2 ms 3468 KB
1_14.txt AC 2 ms 3592 KB
1_15.txt AC 2 ms 3616 KB
1_16.txt AC 2 ms 3488 KB
1_17.txt AC 3 ms 3488 KB
1_18.txt AC 2 ms 3488 KB
1_19.txt AC 2 ms 3576 KB
1_20.txt AC 2 ms 3564 KB
1_21.txt AC 2 ms 3544 KB
1_22.txt AC 2 ms 3620 KB
1_23.txt AC 2 ms 3560 KB
1_24.txt AC 2 ms 3572 KB
1_25.txt AC 6 ms 3696 KB
1_26.txt AC 2 ms 3600 KB
1_27.txt AC 4 ms 3560 KB
1_28.txt AC 5 ms 3536 KB
1_29.txt AC 9 ms 3600 KB
1_30.txt AC 5 ms 3588 KB
1_31.txt AC 8 ms 3608 KB
1_32.txt AC 5 ms 3724 KB
1_33.txt AC 3 ms 3560 KB
1_34.txt AC 6 ms 3536 KB
1_35.txt AC 7 ms 3540 KB
1_36.txt AC 7 ms 3708 KB
1_37.txt AC 9 ms 3652 KB
1_38.txt AC 7 ms 3556 KB
1_39.txt AC 7 ms 3752 KB
1_40.txt AC 2 ms 3596 KB