Submission #3196151


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].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 = 0; i < s.size(); ++i) {
      for (int j = i + 1; j < s.size(); ++j) {
        if (!g[i].count(s[j])) {
          g[i][s[j]] = j;
        }
      }
    }

    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 1627 Byte
Status TLE
Exec Time 2103 ms
Memory 13568 KB

Judge Result

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