답안 #528962

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
528962 2022-02-21T20:43:19 Z jeremias Type Printer (IOI08_printer) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forsn(i, s, n) for (int i = int(s); i < int(n); i++)
#define all(x) x.begin(), x.end()
#define LSB(x) x & -x
typedef long long ll;
using namespace std;

/**
Trie
traverse in sorted order
**/

const MAXN = 20 * 25001;
int trie[MAXN][27], d[MAXN], nxt = 1, rta = 0;
bool isWord[MAXN], dont[MAXN];
string longest = "";

void insert(string &s)
{
    int i = 0, v = 0;
    while (i < s.size())
    {
        if (trie[v][(s[i]-'a')] == -1)
        {
            trie[v][(s[i]-'a')] = nxt++;
        }
        v = trie[v][(s[i++]-'a')];
    }
    isWord[v] = true;
}

void depths(int node, int depth)
{
    d[node] = depth;
    forn(i, 26)
    {
        if (trie[node][i] != -1)
        {
            depths(trie[node][i], depth + 1);
        }
    }
}

void dfs(int node)
{
    int d_it = -1;
    forn(i, 26)
    {
        if (trie[node][i] != -1)
        {
            if (!dont[trie[node][i]])
            {
                rta++;
                cout << (char)(i + 'a') << "\n";
                if(isWord[trie[node][i]]){
                    cout << "P\n";
                    rta++;
                }
                dfs(trie[node][i]);
                rta++;
                cout << "-\n";
            }
            else
                d_it = i;
        }
    }
    if (d_it != -1){
        rta++;
        cout << (char)(d_it + 'a') << "\n";
        if(isWord[trie[node][d_it]]){
            cout << "P\n";
            rta++;
        }
        dfs(trie[node][d_it]);
    }
}

int main()
{
    iostream::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    memset(trie, -1, sizeof(trie));
    memset(isWord, false, sizeof(isWord));
    memset(dont, false, sizeof(dont));
    forn(i, n)
    {
        string s;
        cin >> s;
        insert(s);
        if (s.size() > longest.size())
        {
            longest = s;
        }
    }
    int v = 0;
    forn(i, longest.size())
    {
        v = trie[v][longest[i] - 'a'];
        dont[v] = true;
    }
    // declare depths
    depths(0, 0);
    // dfs
    dfs(0);
    // display
    cout << rta;

    return 0;
}

/*
 */

Compilation message

printer.cpp:14:7: error: 'MAXN' does not name a type
   14 | const MAXN = 20 * 25001;
      |       ^~~~
printer.cpp:15:10: error: 'MAXN' was not declared in this scope
   15 | int trie[MAXN][27], d[MAXN], nxt = 1, rta = 0;
      |          ^~~~
printer.cpp:15:23: error: 'MAXN' was not declared in this scope
   15 | int trie[MAXN][27], d[MAXN], nxt = 1, rta = 0;
      |                       ^~~~
printer.cpp:16:13: error: 'MAXN' was not declared in this scope
   16 | bool isWord[MAXN], dont[MAXN];
      |             ^~~~
printer.cpp:16:25: error: 'MAXN' was not declared in this scope
   16 | bool isWord[MAXN], dont[MAXN];
      |                         ^~~~
printer.cpp: In function 'void insert(std::string&)':
printer.cpp:22:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     while (i < s.size())
      |            ~~^~~~~~~~~~
printer.cpp:24:13: error: 'trie' was not declared in this scope
   24 |         if (trie[v][(s[i]-'a')] == -1)
      |             ^~~~
printer.cpp:28:13: error: 'trie' was not declared in this scope
   28 |         v = trie[v][(s[i++]-'a')];
      |             ^~~~
printer.cpp:30:5: error: 'isWord' was not declared in this scope
   30 |     isWord[v] = true;
      |     ^~~~~~
printer.cpp: In function 'void depths(int, int)':
printer.cpp:35:5: error: 'd' was not declared in this scope
   35 |     d[node] = depth;
      |     ^
printer.cpp:38:13: error: 'trie' was not declared in this scope
   38 |         if (trie[node][i] != -1)
      |             ^~~~
printer.cpp: In function 'void dfs(int)':
printer.cpp:50:13: error: 'trie' was not declared in this scope
   50 |         if (trie[node][i] != -1)
      |             ^~~~
printer.cpp:52:18: error: 'dont' was not declared in this scope
   52 |             if (!dont[trie[node][i]])
      |                  ^~~~
printer.cpp:56:20: error: 'isWord' was not declared in this scope
   56 |                 if(isWord[trie[node][i]]){
      |                    ^~~~~~
printer.cpp:71:12: error: 'isWord' was not declared in this scope
   71 |         if(isWord[trie[node][d_it]]){
      |            ^~~~~~
printer.cpp:71:19: error: 'trie' was not declared in this scope
   71 |         if(isWord[trie[node][d_it]]){
      |                   ^~~~
printer.cpp:75:13: error: 'trie' was not declared in this scope
   75 |         dfs(trie[node][d_it]);
      |             ^~~~
printer.cpp: In function 'int main()':
printer.cpp:85:12: error: 'trie' was not declared in this scope
   85 |     memset(trie, -1, sizeof(trie));
      |            ^~~~
printer.cpp:86:12: error: 'isWord' was not declared in this scope
   86 |     memset(isWord, false, sizeof(isWord));
      |            ^~~~~~
printer.cpp:87:12: error: 'dont' was not declared in this scope
   87 |     memset(dont, false, sizeof(dont));
      |            ^~~~