Submission #8461764


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int32 n;
string s;

int32 bfs(int32 i, deque<int32> que){
    if(i == n){
        return que.size();
    }
    if(que.empty()){
        que.push_back(s[i]);
        return bfs(i+1,que);
    }else if(s[i] == que.front()){
        que.pop_front();
        return bfs(i+1, que);
    }else if(s[i] == que.back()){
        que.pop_back();
        return bfs(i+1, que);
    }else{
        que.push_front(s[i]);
        int32 retval = bfs(i+1, que);
        que.pop_front();
        que.push_back(s[i]);
        retval = min(retval, bfs(i+1, que));
        return retval;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cin >> s;
    cout << bfs(0, deque<int32>()) << endl;
    return 0;
}

Submission Info

Submission Time
Task C - 魂の還る場所
User HayatoY
Language C++14 (GCC 5.4.1)
Score 30
Code Size 1379 Byte
Status TLE
Exec Time 2103 ms
Memory 256 KB

Judge Result

Set Name part1 part2
Score / Max Score 30 / 30 0 / 70
Status
AC × 39
AC × 60
TLE × 12
Set Name Test Cases
part1 level1/level1_00_sample_01.txt, level1/level1_00_sample_02.txt, level1/level1_01_max_01.txt, level1/level1_01_max_02.txt, level1/level1_01_max_03.txt, level1/level1_01_min2.txt, level1/level1_01_min_01.txt, level1/level1_01_min_02.txt, level1/level1_01_min_03.txt, level1/level1_02_rand_00.txt, level1/level1_02_rand_01.txt, level1/level1_02_rand_02.txt, level1/level1_02_rand_03.txt, level1/level1_02_rand_04.txt, level1/level1_02_rand_05.txt, level1/level1_02_rand_06.txt, level1/level1_02_rand_07.txt, level1/level1_02_rand_08.txt, level1/level1_02_rand_09.txt, level1/level1_02_rand_10.txt, level1/level1_02_rand_11.txt, level1/level1_02_rand_12.txt, level1/level1_02_rand_13.txt, level1/level1_02_rand_14.txt, level1/level1_03_rand_00.txt, level1/level1_03_rand_01.txt, level1/level1_03_rand_02.txt, level1/level1_03_rand_03.txt, level1/level1_03_rand_04.txt, level1/level1_03_rand_05.txt, level1/level1_03_rand_06.txt, level1/level1_03_rand_07.txt, level1/level1_03_rand_08.txt, level1/level1_03_rand_09.txt, level1/level1_03_rand_10.txt, level1/level1_03_rand_11.txt, level1/level1_03_rand_12.txt, level1/level1_03_rand_13.txt, level1/level1_03_rand_14.txt
part2 level1/level1_00_sample_01.txt, level1/level1_00_sample_02.txt, level1/level1_01_max_01.txt, level1/level1_01_max_02.txt, level1/level1_01_max_03.txt, level1/level1_01_min2.txt, level1/level1_01_min_01.txt, level1/level1_01_min_02.txt, level1/level1_01_min_03.txt, level1/level1_02_rand_00.txt, level1/level1_02_rand_01.txt, level1/level1_02_rand_02.txt, level1/level1_02_rand_03.txt, level1/level1_02_rand_04.txt, level1/level1_02_rand_05.txt, level1/level1_02_rand_06.txt, level1/level1_02_rand_07.txt, level1/level1_02_rand_08.txt, level1/level1_02_rand_09.txt, level1/level1_02_rand_10.txt, level1/level1_02_rand_11.txt, level1/level1_02_rand_12.txt, level1/level1_02_rand_13.txt, level1/level1_02_rand_14.txt, level1/level1_03_rand_00.txt, level1/level1_03_rand_01.txt, level1/level1_03_rand_02.txt, level1/level1_03_rand_03.txt, level1/level1_03_rand_04.txt, level1/level1_03_rand_05.txt, level1/level1_03_rand_06.txt, level1/level1_03_rand_07.txt, level1/level1_03_rand_08.txt, level1/level1_03_rand_09.txt, level1/level1_03_rand_10.txt, level1/level1_03_rand_11.txt, level1/level1_03_rand_12.txt, level1/level1_03_rand_13.txt, level1/level1_03_rand_14.txt, level2/level2_01_max_01.txt, level2/level2_01_max_02.txt, level2/level2_01_max_03.txt, level2/level2_02_rand_00.txt, level2/level2_02_rand_01.txt, level2/level2_02_rand_02.txt, level2/level2_02_rand_03.txt, level2/level2_02_rand_04.txt, level2/level2_02_rand_05.txt, level2/level2_02_rand_06.txt, level2/level2_02_rand_07.txt, level2/level2_02_rand_08.txt, level2/level2_02_rand_09.txt, level2/level2_02_rand_10.txt, level2/level2_02_rand_11.txt, level2/level2_02_rand_12.txt, level2/level2_02_rand_13.txt, level2/level2_02_rand_14.txt, level2/level2_03_rand_00.txt, level2/level2_03_rand_01.txt, level2/level2_03_rand_02.txt, level2/level2_03_rand_03.txt, level2/level2_03_rand_04.txt, level2/level2_03_rand_05.txt, level2/level2_03_rand_06.txt, level2/level2_03_rand_07.txt, level2/level2_03_rand_08.txt, level2/level2_03_rand_09.txt, level2/level2_03_rand_10.txt, level2/level2_03_rand_11.txt, level2/level2_03_rand_12.txt, level2/level2_03_rand_13.txt, level2/level2_03_rand_14.txt
Case Name Status Exec Time Memory
level1/level1_00_sample_01.txt AC 1 ms 256 KB
level1/level1_00_sample_02.txt AC 1 ms 256 KB
level1/level1_01_max_01.txt AC 1 ms 256 KB
level1/level1_01_max_02.txt AC 1 ms 256 KB
level1/level1_01_max_03.txt AC 1 ms 256 KB
level1/level1_01_min2.txt AC 1 ms 256 KB
level1/level1_01_min_01.txt AC 1 ms 256 KB
level1/level1_01_min_02.txt AC 1 ms 256 KB
level1/level1_01_min_03.txt AC 1 ms 256 KB
level1/level1_02_rand_00.txt AC 1 ms 256 KB
level1/level1_02_rand_01.txt AC 1 ms 256 KB
level1/level1_02_rand_02.txt AC 1 ms 256 KB
level1/level1_02_rand_03.txt AC 1 ms 256 KB
level1/level1_02_rand_04.txt AC 1 ms 256 KB
level1/level1_02_rand_05.txt AC 1 ms 256 KB
level1/level1_02_rand_06.txt AC 1 ms 256 KB
level1/level1_02_rand_07.txt AC 1 ms 256 KB
level1/level1_02_rand_08.txt AC 1 ms 256 KB
level1/level1_02_rand_09.txt AC 1 ms 256 KB
level1/level1_02_rand_10.txt AC 1 ms 256 KB
level1/level1_02_rand_11.txt AC 1 ms 256 KB
level1/level1_02_rand_12.txt AC 1 ms 256 KB
level1/level1_02_rand_13.txt AC 1 ms 256 KB
level1/level1_02_rand_14.txt AC 1 ms 256 KB
level1/level1_03_rand_00.txt AC 1 ms 256 KB
level1/level1_03_rand_01.txt AC 1 ms 256 KB
level1/level1_03_rand_02.txt AC 1 ms 256 KB
level1/level1_03_rand_03.txt AC 1 ms 256 KB
level1/level1_03_rand_04.txt AC 1 ms 256 KB
level1/level1_03_rand_05.txt AC 1 ms 256 KB
level1/level1_03_rand_06.txt AC 1 ms 256 KB
level1/level1_03_rand_07.txt AC 1 ms 256 KB
level1/level1_03_rand_08.txt AC 1 ms 256 KB
level1/level1_03_rand_09.txt AC 1 ms 256 KB
level1/level1_03_rand_10.txt AC 1 ms 256 KB
level1/level1_03_rand_11.txt AC 1 ms 256 KB
level1/level1_03_rand_12.txt AC 1 ms 256 KB
level1/level1_03_rand_13.txt AC 1 ms 256 KB
level1/level1_03_rand_14.txt AC 1 ms 256 KB
level2/level2_01_max_01.txt AC 1 ms 256 KB
level2/level2_01_max_02.txt AC 1 ms 256 KB
level2/level2_01_max_03.txt AC 1 ms 256 KB
level2/level2_02_rand_00.txt AC 1 ms 256 KB
level2/level2_02_rand_01.txt AC 2 ms 256 KB
level2/level2_02_rand_02.txt AC 5 ms 256 KB
level2/level2_02_rand_03.txt AC 2 ms 256 KB
level2/level2_02_rand_04.txt AC 2 ms 256 KB
level2/level2_02_rand_05.txt AC 1 ms 256 KB
level2/level2_02_rand_06.txt AC 1 ms 256 KB
level2/level2_02_rand_07.txt TLE 2103 ms 256 KB
level2/level2_02_rand_08.txt AC 14 ms 256 KB
level2/level2_02_rand_09.txt AC 1 ms 256 KB
level2/level2_02_rand_10.txt AC 4 ms 256 KB
level2/level2_02_rand_11.txt AC 1 ms 256 KB
level2/level2_02_rand_12.txt TLE 2103 ms 256 KB
level2/level2_02_rand_13.txt AC 221 ms 256 KB
level2/level2_02_rand_14.txt AC 1 ms 256 KB
level2/level2_03_rand_00.txt TLE 2103 ms 256 KB
level2/level2_03_rand_01.txt AC 1321 ms 256 KB
level2/level2_03_rand_02.txt TLE 2103 ms 256 KB
level2/level2_03_rand_03.txt AC 114 ms 256 KB
level2/level2_03_rand_04.txt TLE 2103 ms 256 KB
level2/level2_03_rand_05.txt TLE 2103 ms 256 KB
level2/level2_03_rand_06.txt TLE 2103 ms 256 KB
level2/level2_03_rand_07.txt TLE 2103 ms 256 KB
level2/level2_03_rand_08.txt TLE 2103 ms 256 KB
level2/level2_03_rand_09.txt TLE 2103 ms 256 KB
level2/level2_03_rand_10.txt TLE 2103 ms 256 KB
level2/level2_03_rand_11.txt AC 1458 ms 256 KB
level2/level2_03_rand_12.txt AC 1288 ms 256 KB
level2/level2_03_rand_13.txt TLE 2103 ms 256 KB
level2/level2_03_rand_14.txt AC 297 ms 256 KB