Submission #3196277


Source Code Expand

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template<typename T>
ostream& operator << (ostream& os, vector<T> v)
{
  os << "(";
  each (i, v) os << i << ",";
  os << ")";
  return os;
}

const int N = 2 * 1e5 + 5;
map<char, int> g[N];

const int inf = 1 << 28;
int memo[N];
int path[N];
int rec(int curr)
{
  int& ret = memo[curr];
  if (ret != -1) return ret;

  for (char c = 'a'; c <= 'z'; ++c) {
    if (!g[curr][c]) {
      path[curr] = -1 * int(c);
      return ret = 0;
    }
  }

  int mn = inf;
  for (char c = 'a'; c <= 'z'; ++c) {
    int len = rec(g[curr][c]) + 1;
    if (len < mn) {
      mn = len;
      path[curr] = g[curr][c];
    }
  }
  return ret = mn;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  string s;
  while (cin >> s) {
    s = "@" + s;

    fill(g, g + N, map<char, int>());
    for (int i = s.size() - 2; 0 <= i; --i) {
      g[i] = g[i + 1];
      g[i][s[i + 1]] = i + 1;
    }

    fill(memo, memo + N, -1);
    fill(path, path + N, -1);
    rec(0);
    for (int i = 0; ; i = path[i]) {
      if (i < 0) {
        cout << (char)abs(i);
        break;
      }
      if (i) cout << s[i];
    }
    cout << endl;
  }

  return 0;
}

Submission Info

Submission Time
Task E - Don't Be a Subsequence
User Johniel
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1607 Byte
Status MLE
Exec Time 509 ms
Memory 255824 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 3
AC × 14
MLE × 22
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, 1.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 2.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 3.txt, 30.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
1.txt AC 7 ms 11264 KB
10.txt MLE 491 ms 255824 KB
11.txt MLE 499 ms 255824 KB
12.txt AC 496 ms 254288 KB
13.txt MLE 502 ms 255824 KB
14.txt MLE 498 ms 255824 KB
15.txt MLE 509 ms 255824 KB
16.txt MLE 503 ms 255824 KB
17.txt MLE 503 ms 255824 KB
18.txt MLE 501 ms 255824 KB
19.txt MLE 508 ms 255824 KB
2.txt AC 9 ms 12416 KB
20.txt MLE 503 ms 255824 KB
21.txt MLE 490 ms 255824 KB
22.txt MLE 500 ms 255824 KB
23.txt MLE 505 ms 255824 KB
24.txt MLE 497 ms 255824 KB
25.txt MLE 500 ms 255696 KB
26.txt MLE 494 ms 255440 KB
27.txt MLE 497 ms 255568 KB
28.txt MLE 492 ms 255696 KB
29.txt MLE 499 ms 255568 KB
3.txt AC 29 ms 23424 KB
30.txt AC 424 ms 251472 KB
4.txt AC 29 ms 23424 KB
5.txt AC 250 ms 133484 KB
6.txt AC 257 ms 133484 KB
7.txt MLE 503 ms 255824 KB
8.txt MLE 495 ms 255824 KB
9.txt MLE 499 ms 255824 KB
sample1.txt AC 7 ms 11264 KB
sample2.txt AC 7 ms 11264 KB
sample3.txt AC 8 ms 11392 KB