# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
303155 | 2020-09-19T23:20:35 Z | FlashGamezzz | Type Printer (IOI08_printer) | C++17 | 1000 ms | 111112 KB |
#include <iostream> #include <cstdlib> #include <cstdio> #include <fstream> #include <algorithm> #include <string> #include <utility> #include <vector> #include <queue> using namespace std; vector< vector<long> > lets; vector<bool> endb; vector<int> length; vector<char> ans; void add(long c, int i, string s){ if (i == s.length()){ endb[c] = true; length[c] = 0; return; } int l = int(s[i])-97; if (lets[c][l] == 0){ vector<long> t; for (int j = 0; j < 26; j++) t.push_back(0); lets.push_back(t); endb.push_back(false); length.push_back(-100); lets[c][l] = lets.size()-1; } add(lets[c][l], i+1, s); length[c] = max(length[lets[c][l]]+1, length[c]); } void solve(long c){ if (endb[c]){ ans.push_back('P'); } vector< pair<int, int> > ls; for (int i = 0; i < 26; i++){ if (lets[c][i] != 0){ ls.push_back(make_pair(length[lets[c][i]], i)); } } sort(ls.begin(), ls.end()); for (pair<int, int> a : ls){ ans.push_back(char(a.second+97)); solve(lets[c][a.second]); ans.push_back('-'); } } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; vector<long> t; for (int j = 0; j < 26; j++) t.push_back(0); lets.push_back(t); endb.push_back(false); length.push_back(-100); for (int i = 0; i < n; i++){ string s; cin >> s; add(0, 0, s); } solve(0); long count = ans.size(); while (ans[count-1] == '-'){ count--; } cout << count << endl; for (int i = 0; i < count; i++){ cout << ans[i] << endl; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 512 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 36 ms | 2048 KB | Output is correct |
2 | Incorrect | 48 ms | 2560 KB | Output isn't correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 135 ms | 6704 KB | Output is correct |
2 | Correct | 281 ms | 13992 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 342 ms | 16684 KB | Output is correct |
2 | Correct | 99 ms | 3644 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 868 ms | 41552 KB | Output is correct |
2 | Execution timed out | 1095 ms | 93832 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 701 ms | 32420 KB | Output is correct |
2 | Execution timed out | 1107 ms | 111112 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |