Submission #1030592

# Submission time Handle Problem Language Result Execution time Memory
1030592 2024-07-22T07:15:56 Z fuad27 Vim (BOI13_vim) C++17
35.5 / 100
89 ms 59732 KB
#include <bits/stdc++.h>
using namespace std;
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
 
template <typename T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define vt vector
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
template<class T> bool chmin(T& a, const T& b) {
	return b<a?a=b, 1:0;
}
template<class T> bool chmax(T& a, const T& b) { 
	return a<b?a=b, 1:0;
} 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

int k(int a, int b) {
 if(a==b)return 1e9;
 return 0;
}
int u(int v) {
  if(v)return 1e9;
  return 0;
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);
  int n;
  string s;
  cin >> n >> s;
  int ans=0;
  reverse(all(s));
  while(sz(s) and s.back() == 'e') {
    ans++;
    s.pop_back();
  }
  reverse(all(s));
  vt<bool> need(n);
  {
    string tmp = "";
    for(int i = 0;i<n;i++) {
      if(s[i] == 'e') {
        ans+=2;
        continue;
      }
      if(i == 0 or s[i-1] == 'e') {
        need[tmp.size()]=1;
      }
      tmp.push_back(s[i]);
      tmp.back()-='a';
    }
    swap(tmp, s);
  }
  n=s.size();
  vt dp2(n+1, vt(12, vt(12, 0)));
  vt dp1(n+1, vt(12, (int)1e9));
  for(int i = 0;i<12;i++) {
    if(s[i] != i)dp1[0][i] = 2;
  }
 for(int i = 0;i<n;i++) {
    for(int j = 0;j<12;j++) {
      dp1[i+1][j] = min({dp1[i][j] + k(s[i], j) + u(need[i]), dp1[i][s[i]] + 2, dp2[i][s[i]][j]+k(s[i], j), dp2[i][s[i]][s[i]]+2});
      for(int l = 0;l<12;l++) {
        dp2[i+1][j][l] = min({dp1[i][j] + 3 + k(j, s[i]), dp1[i][s[i]] + 5,
            dp2[i][j][l]+1  + k(j, s[i]) + k(l, s[i]), dp2[i][j][s[i]]+3+k(j, s[i]), dp2[i][s[i]][l]+3+k(l, s[i]), dp2[i][s[i]][s[i]]+5});
      }
    }
  }
 ans+=dp1[n][11];
 cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Correct 1 ms 604 KB Output is correct
3 Incorrect 1 ms 604 KB Output isn't correct
4 Correct 1 ms 604 KB Output is correct
5 Incorrect 1 ms 604 KB Output isn't correct
6 Incorrect 1 ms 604 KB Output isn't correct
7 Incorrect 1 ms 604 KB Output isn't correct
8 Incorrect 0 ms 348 KB Output isn't correct
9 Incorrect 0 ms 348 KB Output isn't correct
10 Incorrect 0 ms 348 KB Output isn't correct
11 Correct 0 ms 348 KB Output is correct
12 Incorrect 0 ms 348 KB Output isn't correct
13 Incorrect 1 ms 604 KB Output isn't correct
14 Correct 1 ms 604 KB Output is correct
15 Incorrect 1 ms 604 KB Output isn't correct
16 Incorrect 1 ms 604 KB Output isn't correct
17 Incorrect 1 ms 604 KB Output isn't correct
18 Incorrect 1 ms 604 KB Output isn't correct
19 Incorrect 0 ms 604 KB Output isn't correct
20 Incorrect 1 ms 604 KB Output isn't correct
21 Correct 1 ms 604 KB Output is correct
22 Incorrect 1 ms 600 KB Output isn't correct
23 Incorrect 1 ms 860 KB Output isn't correct
24 Incorrect 1 ms 860 KB Output isn't correct
25 Incorrect 1 ms 604 KB Output isn't correct
26 Correct 1 ms 604 KB Output is correct
27 Incorrect 1 ms 600 KB Output isn't correct
28 Incorrect 1 ms 604 KB Output isn't correct
29 Incorrect 1 ms 600 KB Output isn't correct
30 Correct 1 ms 860 KB Output is correct
31 Incorrect 1 ms 604 KB Output isn't correct
32 Incorrect 1 ms 860 KB Output isn't correct
33 Correct 1 ms 860 KB Output is correct
34 Correct 1 ms 604 KB Output is correct
35 Incorrect 1 ms 604 KB Output isn't correct
36 Incorrect 1 ms 604 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2396 KB Output isn't correct
2 Incorrect 4 ms 3420 KB Output isn't correct
3 Correct 2 ms 1884 KB Output is correct
4 Incorrect 3 ms 2612 KB Output isn't correct
5 Incorrect 5 ms 3420 KB Output isn't correct
6 Correct 6 ms 4444 KB Output is correct
7 Correct 4 ms 3152 KB Output is correct
8 Incorrect 4 ms 3164 KB Output isn't correct
9 Incorrect 5 ms 3420 KB Output isn't correct
10 Incorrect 4 ms 3672 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 52056 KB Output is correct
2 Incorrect 66 ms 49844 KB Output isn't correct
3 Correct 69 ms 52812 KB Output is correct
4 Incorrect 69 ms 53588 KB Output isn't correct
5 Correct 77 ms 59728 KB Output is correct
6 Incorrect 35 ms 27180 KB Output isn't correct
7 Incorrect 57 ms 44636 KB Output isn't correct
8 Incorrect 67 ms 52048 KB Output isn't correct
9 Correct 54 ms 38492 KB Output is correct
10 Incorrect 51 ms 36444 KB Output isn't correct
11 Incorrect 69 ms 53592 KB Output isn't correct
12 Correct 89 ms 59732 KB Output is correct
13 Correct 75 ms 58704 KB Output is correct
14 Correct 75 ms 57680 KB Output is correct
15 Correct 64 ms 48464 KB Output is correct
16 Incorrect 69 ms 52816 KB Output isn't correct
17 Correct 68 ms 51988 KB Output is correct
18 Correct 68 ms 52824 KB Output is correct
19 Incorrect 64 ms 49744 KB Output isn't correct
20 Incorrect 56 ms 42120 KB Output isn't correct