Submission #23839033


Source Code Expand

#include <bits/stdc++.h>
//#include <atcoder/all>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e18;
//const ll mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    string S;
    cin >> N >> S;
    if(S[0] != S[N-1]) {
        cout << 1 << endl;
        return 0;
    }
    char c = S[0];
    for(int i = 0; i + 1 < N; i++) {
        if(S[i] != c and S[i+1] != c) {
            cout << 2 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Submission Info

Submission Time
Task A - Remove Substrings
User kort0n
Language C++ (GCC 9.2.1)
Score 300
Code Size 865 Byte
Status AC
Exec Time 11 ms
Memory 3772 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 16
Set Name Test Cases
Sample 00-sample-001.txt, 00-sample-002.txt
All 00-sample-001.txt, 00-sample-002.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt
Case Name Status Exec Time Memory
00-sample-001.txt AC 11 ms 3488 KiB
00-sample-002.txt AC 2 ms 3436 KiB
01-001.txt AC 2 ms 3568 KiB
01-002.txt AC 2 ms 3568 KiB
01-003.txt AC 2 ms 3676 KiB
01-004.txt AC 4 ms 3544 KiB
01-005.txt AC 3 ms 3624 KiB
01-006.txt AC 3 ms 3772 KiB
01-007.txt AC 2 ms 3676 KiB
01-008.txt AC 4 ms 3688 KiB
01-009.txt AC 2 ms 3660 KiB
01-010.txt AC 2 ms 3676 KiB
01-011.txt AC 4 ms 3740 KiB
01-012.txt AC 2 ms 3616 KiB
01-013.txt AC 2 ms 3696 KiB
01-014.txt AC 3 ms 3604 KiB