답안 #44245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
44245 2018-03-30T20:43:31 Z neutron_byte Vim (BOI13_vim) C++17
4.16667 / 100
2000 ms 1276 KB
#include <bits/stdc++.h>
#define INF 10000000
using namespace std;

int main() {
    int n; cin >> n;
    string s; cin >> s;

    int dp[n];
    dp[n - 1] = 0;

    for (int i = n - 2; i >= 0; --i) {
        if (s[i] == 'e') {
            dp[i] = 1 + dp[i + 1];
            continue;
        }

        dp[i] = INF;

        // check all possibilities to jump
        for (char c = 'a'; c <= 'j'; ++c) {
            if (c == 'e') continue;

            // find next occurrence
            int pos = i + 1;
            while (pos < n && s[pos] != c) {
                ++pos;
            }

            if (pos >= n) {
                continue;
            }

            // jump from i to pos

            int firstE = -1;
            int cntE = 0;

            for (int j = pos - 1; j > i; --j) {
                if (s[j] == 'e') {
                    ++cntE;
                    firstE = j;
                }
            }

            bool onlyE = true;
            for (int j = pos - 1; j >= firstE; --j) {
                if (s[j] != 'e') {
                    onlyE = false;
                    break;
                }
            }

            int afterE = 0;
            for (int j = pos + 1; j < n; ++j) {
                if (s[j] == 'e') ++afterE;
            }

            if (afterE > 0) {
                for (char d = 'a'; d <= 'j'; ++d) {
                    if (d == 'e') continue;
                    bool betweenE = false;
                    int nextOcc = -1;
                    for (int j = i + 1; j < n; ++j) {
                        if (s[j] == d) {
                            nextOcc = j;
                            break;
                        }
                    }

                    if (nextOcc == -1 || nextOcc < pos) continue;
                    for (int j = pos + 1; j <= nextOcc; ++j) {
                        if (s[j] == 'e') {
                            betweenE = true;
                            break;
                        }
                    }

                    if (!betweenE) {
                        if (cntE > 0) dp[i] = min(dp[i], (onlyE ? 2 : 4) + pos - firstE + cntE + dp[nextOcc]);
                        else dp[i] = min(dp[i], 2 + dp[nextOcc]);
                    }
                }

            } else {
                if (cntE > 0) dp[i] = min(dp[i], 2 + pos - firstE + cntE);
                else dp[i] = 0;
            }
        }

/*
            if (cntE > 0) {
                if (afterE > 0) {
                    dp[i] = min(dp[i], (onlyE ? 2 : 4) + pos - firstE + cntE + dp[pos]);
                } else {
                    dp[i] = min(dp[i], 2 + pos - firstE + cntE);
                }
            } else {
                if (afterE > 0) {
                    dp[i] = min(dp[i], 2 + dp[pos]);
                } else {
                    dp[i] = 0;
                }
            }
        }
*/
    }

/*
    for (int i = 0; i < n; ++i) {
        cout << "dp[" << i << "] = " << dp[i] << endl;
    }
*/

    cout << dp[0] << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 252 KB Output isn't correct
2 Incorrect 4 ms 356 KB Output isn't correct
3 Incorrect 4 ms 356 KB Output isn't correct
4 Incorrect 3 ms 408 KB Output isn't correct
5 Incorrect 4 ms 596 KB Output isn't correct
6 Incorrect 3 ms 596 KB Output isn't correct
7 Incorrect 4 ms 596 KB Output isn't correct
8 Correct 2 ms 596 KB Output is correct
9 Incorrect 2 ms 628 KB Output isn't correct
10 Incorrect 2 ms 628 KB Output isn't correct
11 Incorrect 2 ms 628 KB Output isn't correct
12 Correct 2 ms 628 KB Output is correct
13 Incorrect 4 ms 628 KB Output isn't correct
14 Incorrect 4 ms 628 KB Output isn't correct
15 Incorrect 3 ms 628 KB Output isn't correct
16 Incorrect 4 ms 628 KB Output isn't correct
17 Incorrect 4 ms 628 KB Output isn't correct
18 Incorrect 3 ms 628 KB Output isn't correct
19 Incorrect 3 ms 628 KB Output isn't correct
20 Incorrect 3 ms 628 KB Output isn't correct
21 Incorrect 3 ms 628 KB Output isn't correct
22 Incorrect 3 ms 628 KB Output isn't correct
23 Incorrect 6 ms 628 KB Output isn't correct
24 Incorrect 4 ms 628 KB Output isn't correct
25 Incorrect 4 ms 628 KB Output isn't correct
26 Incorrect 4 ms 628 KB Output isn't correct
27 Incorrect 3 ms 628 KB Output isn't correct
28 Incorrect 3 ms 628 KB Output isn't correct
29 Incorrect 4 ms 628 KB Output isn't correct
30 Incorrect 5 ms 628 KB Output isn't correct
31 Incorrect 4 ms 628 KB Output isn't correct
32 Correct 4 ms 628 KB Output is correct
33 Incorrect 4 ms 628 KB Output isn't correct
34 Incorrect 3 ms 628 KB Output isn't correct
35 Incorrect 3 ms 628 KB Output isn't correct
36 Incorrect 4 ms 628 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 47 ms 764 KB Output isn't correct
2 Incorrect 66 ms 764 KB Output isn't correct
3 Incorrect 23 ms 764 KB Output isn't correct
4 Incorrect 47 ms 764 KB Output isn't correct
5 Incorrect 77 ms 764 KB Output isn't correct
6 Incorrect 263 ms 764 KB Output isn't correct
7 Incorrect 76 ms 764 KB Output isn't correct
8 Incorrect 86 ms 764 KB Output isn't correct
9 Incorrect 61 ms 764 KB Output isn't correct
10 Incorrect 131 ms 764 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2082 ms 1028 KB Time limit exceeded
2 Execution timed out 2080 ms 1148 KB Time limit exceeded
3 Execution timed out 2071 ms 1148 KB Time limit exceeded
4 Execution timed out 2065 ms 1152 KB Time limit exceeded
5 Execution timed out 2078 ms 1152 KB Time limit exceeded
6 Execution timed out 2062 ms 1276 KB Time limit exceeded
7 Execution timed out 2066 ms 1276 KB Time limit exceeded
8 Execution timed out 2068 ms 1276 KB Time limit exceeded
9 Execution timed out 2064 ms 1276 KB Time limit exceeded
10 Execution timed out 2056 ms 1276 KB Time limit exceeded
11 Execution timed out 2061 ms 1276 KB Time limit exceeded
12 Execution timed out 2060 ms 1276 KB Time limit exceeded
13 Execution timed out 2050 ms 1276 KB Time limit exceeded
14 Execution timed out 2071 ms 1276 KB Time limit exceeded
15 Execution timed out 2063 ms 1276 KB Time limit exceeded
16 Execution timed out 2072 ms 1276 KB Time limit exceeded
17 Execution timed out 2061 ms 1276 KB Time limit exceeded
18 Execution timed out 2053 ms 1276 KB Time limit exceeded
19 Execution timed out 2052 ms 1276 KB Time limit exceeded
20 Execution timed out 2071 ms 1276 KB Time limit exceeded