답안 #403233

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
403233 2021-05-13T00:02:11 Z Lobo Miners (IOI07_miners) C++17
52 / 100
2 ms 972 KB
#include <bits/stdc++.h>
 
using namespace std;

const long long INFll = 1e18;
const int INFii = 1e9;
const long long mod = (long long) 1e9 + 7;
typedef long long ll;
typedef int ii;
typedef double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back

#define maxn 110
//LEMBRAR DE MUDAR

ii n;
string s;
map<pair<pair<char,char>,pair<char,char>>, ll> dp[maxn];

ii sol(ii i, char a1, char a2, char b1, char b2) {
    if(i == n) return 0;

    if(dp[i].find(mp(mp(a1,a2),mp(b1,b2))) != dp[i].end()) {
        return dp[i][mp(mp(a1,a2),mp(b1,b2))];
    }

    set<char> st1;

    if(a1 != '0') st1.insert(a1);
    if(a2 != '0') st1.insert(a2);
    st1.insert(s[i]);
    ii p1 = st1.size();


    set<char> st2;

    if(b1 != '0') st2.insert(b1);
    if(b2 != '0') st2.insert(b2);
    st2.insert(s[i]);
    ii p2 = st2.size();

    dp[i][mp(mp(a1,a2),mp(b1,b2))] = max(p1 + sol(i+1, s[i], a1, b1, b2), p2 + sol(i+1, a1, a2, s[i], b1));

    return dp[i][mp(mp(a1,a2),mp(b1,b2))];
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);

    //freopen("in.in", "r", stdin);
    //freopen("____.out", "w", stdout);

    cin >> n;
    cin >> s;

    cout << sol(0, '0', '0', '0', '0') << endl;

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 460 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 584 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 844 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 972 KB Execution killed with signal 11