Submission #3196173


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 * 10000 + 5;
map<char, int> g[N];

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

  int mn = 1 << 29;
  for (char c = 'a'; c <= 'z'; ++c) {
    if (!g[curr][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);
    rec(0);
    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 1552 Byte
Status RE
Exec Time 99 ms
Memory 13568 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 3
AC × 10
RE × 26
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 2 ms 1408 KB
10.txt RE 98 ms 1744 KB
11.txt RE 98 ms 1744 KB
12.txt RE 98 ms 1744 KB
13.txt RE 99 ms 1744 KB
14.txt RE 98 ms 1744 KB
15.txt RE 98 ms 1744 KB
16.txt RE 97 ms 1744 KB
17.txt RE 98 ms 1744 KB
18.txt RE 98 ms 1744 KB
19.txt RE 98 ms 1744 KB
2.txt AC 4 ms 2560 KB
20.txt RE 98 ms 1744 KB
21.txt RE 97 ms 1744 KB
22.txt RE 99 ms 1744 KB
23.txt RE 98 ms 1744 KB
24.txt RE 98 ms 1744 KB
25.txt RE 98 ms 1744 KB
26.txt RE 97 ms 1744 KB
27.txt RE 98 ms 1744 KB
28.txt RE 97 ms 1744 KB
29.txt RE 98 ms 1744 KB
3.txt AC 22 ms 13568 KB
30.txt RE 98 ms 1744 KB
4.txt AC 22 ms 13568 KB
5.txt RE 98 ms 1488 KB
6.txt RE 99 ms 1488 KB
7.txt RE 99 ms 1744 KB
8.txt RE 99 ms 1744 KB
9.txt RE 98 ms 1744 KB
sample1.txt AC 2 ms 1408 KB
sample2.txt AC 2 ms 1408 KB
sample3.txt AC 2 ms 1536 KB