답안 #212279

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
212279 2020-03-22T16:27:32 Z jk89 Type Printer (IOI08_printer) C++14
100 / 100
109 ms 48628 KB
#include <iostream>
#include <cstring>
#include <vector>

using namespace std;

const int MAXN = 5e5 + 3;
const int ALF = 26;
int t[MAXN][ALF];
bool mask[MAXN];
vector<char> odp;

void DFS(int x) {
    if (mask[x])
        odp.push_back('P');
    for (int i = 0; i < ALF; i++) {
        if (t[x][i] != 0) {
            odp.push_back(char(i + 'a'));
            DFS(t[x][i]);
        }
    }
    odp.push_back('-');
}

int main() {
    ios_base::sync_with_stdio(false);
    int n;
    string s, temp;
    cin >> n;
    int ind = 0;
    int akt, x;
    int mx = 0;
    for (int i = 1; i <= n; i++) {
        cin >> s;
        if (s.size() > mx) {
            mx = s.size();
            temp = s;
        }
        akt = 0;
        for (int j = 0; j < s.size(); j++) {
            x = s[j] - 'a';
            if (t[akt][x] != 0)
                akt = t[akt][x];
            else {
                ind++;
                t[akt][x] = ind;
                akt = ind;
            }
        }
        mask[akt] = true;
    }
    akt = 0;
    for (int i = 0; i < mx; i++) {
        for (int j = 0; j < ALF; j++) {
            if (t[akt][j] != 0 && j != temp[i] - 'a') {
                odp.push_back(char(j + 'a'));
                DFS(t[akt][j]);
            }
        }
        akt = t[akt][temp[i] - 'a'];
        odp.push_back(temp[i]);
        if (mask[akt])
            odp.push_back('P');
    }
    cout << odp.size() << '\n';
    for (auto it:odp)
        cout << it << '\n';
    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:35:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (s.size() > mx) {
             ~~~~~~~~~^~~~
printer.cpp:40:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < s.size(); j++) {
                         ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 6 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1152 KB Output is correct
2 Correct 8 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 3200 KB Output is correct
2 Correct 18 ms 6400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 7544 KB Output is correct
2 Correct 11 ms 2048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 18184 KB Output is correct
2 Correct 92 ms 40940 KB Output is correct
3 Correct 65 ms 21364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 14324 KB Output is correct
2 Correct 109 ms 48628 KB Output is correct
3 Correct 72 ms 24308 KB Output is correct
4 Correct 96 ms 45936 KB Output is correct