답안 #418006

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
418006 2021-06-04T20:48:00 Z iulia13 Type Printer (IOI08_printer) C++14
20 / 100
84 ms 39364 KB
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
const int L = 26;
struct nod
{
    int cnt, sons, marked;
    nod *son[L];
    nod()
    {
        cnt = sons = marked = 0;
        for (int i = 0; i < L; i++)
            son[i] = 0;
    }
};
int ans = 0;
vector <char> sol;
nod *trie = new nod;
void update(nod *trie, char *s, int val, int lit, int tip)
{
    int next;
    trie->marked += tip;
    if (!lit)
    {
        trie->cnt += val;
        return;
    }
    if (trie->son[*s - 'a'] == 0)
    {
        trie->son[*s - 'a'] = new nod;
        trie->sons++;
    }
    update((trie->son[*s - 'a']), s + 1, val, lit - 1, tip);
}
int stop = 0;
void dfs(nod *trie)
{
    if (trie->sons == 0)
    {
        sol.push_back('P');
        if (trie->marked == 1)
            stop = 1;
        return;
    }
    int dani = -1;
    for (int i = 0; i < L; i++)
    {
        if (trie->son[i] == 0)
            continue;
        if (trie->son[i]->marked == 1)
            dani = i;
        else
        {
            char x = i + 'a';
            sol.push_back(x);
           /// cout << x << '\n';
            dfs(trie->son[i]);
            sol.push_back('-');
           /// cout << "-" << '\n';
        }
    }
    if (dani == -1)
        return;
    char x = dani + 'a';
    sol.push_back(x);
   /// cout << x << '\n';
    dfs(trie->son[dani]);
}
char s[25005][L];
int main()
{
    int n, i, maxim = -1;
    cin >> n;
    ans = n;
    trie->cnt = 1;
    for (i = 1; i <= n; i++)
    {
        cin >> s[i];
        int aw = strlen(s[i]);
        maxim = max(maxim, aw);
    }
    for (i = 1; i <= n; i++)
    {
        int op = 0, lit = strlen(s[i]);
        if(maxim == lit)
            op = 1, maxim = -1;
        update(trie, s[i], 1, lit, op);
    }
    dfs(trie);
    cout << sol.size() << '\n';
    for (i = 0; i < sol.size(); i++)
        cout << sol[i] << '\n';
    return 0;
}

Compilation message

printer.cpp: In function 'void update(nod*, char*, int, int, int)':
printer.cpp:23:9: warning: unused variable 'next' [-Wunused-variable]
   23 |     int next;
      |         ^~~~
printer.cpp: In function 'int main()':
printer.cpp:93:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |     for (i = 0; i < sol.size(); i++)
      |                 ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Incorrect 0 ms 204 KB didn't print every word
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 1868 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 6308 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 15808 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 84 ms 39364 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 31032 KB didn't print every word
2 Halted 0 ms 0 KB -