Submission #3196216


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 * 100000 + 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;

  int mn = inf;
  for (char c = 'a'; c <= 'z'; ++c) {
    if (!g[curr].count(c)) {
      path[curr] = -1 * int(c);
      return ret = 0;
    }
    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);
    assert(rec(0) < inf);
    string t;
    for (int i = 0; ; i = path[i]) {
      if (i < 0) {
        t += abs(i);
        break;
      }
      t += s[i];
    }
    cout << t.substr(1) << 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 1595 Byte
Status MLE
Exec Time 476 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 463 ms 255824 KB
11.txt MLE 464 ms 255824 KB
12.txt AC 463 ms 254288 KB
13.txt MLE 471 ms 255824 KB
14.txt MLE 466 ms 255824 KB
15.txt MLE 476 ms 255824 KB
16.txt MLE 472 ms 255824 KB
17.txt MLE 470 ms 255824 KB
18.txt MLE 466 ms 255824 KB
19.txt MLE 470 ms 255824 KB
2.txt AC 9 ms 12416 KB
20.txt MLE 471 ms 255824 KB
21.txt MLE 464 ms 255824 KB
22.txt MLE 470 ms 255824 KB
23.txt MLE 467 ms 255824 KB
24.txt MLE 466 ms 255824 KB
25.txt MLE 470 ms 255696 KB
26.txt MLE 467 ms 255568 KB
27.txt MLE 462 ms 255568 KB
28.txt MLE 464 ms 255696 KB
29.txt MLE 471 ms 255568 KB
3.txt AC 29 ms 23424 KB
30.txt AC 416 ms 251728 KB
4.txt AC 28 ms 23424 KB
5.txt AC 236 ms 133484 KB
6.txt AC 240 ms 133484 KB
7.txt MLE 472 ms 255824 KB
8.txt MLE 467 ms 255824 KB
9.txt MLE 471 ms 255824 KB
sample1.txt AC 7 ms 11264 KB
sample2.txt AC 7 ms 11264 KB
sample3.txt AC 7 ms 11392 KB