답안 #397446

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
397446 2021-05-02T08:51:11 Z AugustinasJucas Type Printer (IOI08_printer) C++14
0 / 100
84 ms 54300 KB
#include <bits/stdc++.h>
using namespace std;
struct node {
    bool val = 0;
    int nei[26];
    node() {
        for (int i = 0; i < 26; i++) {
            nei[i] = -1;
        }
    }
};
const int dydis = 5e5 + 100;
node mas[dydis];
int dbInd = 0;
int newN() {
    node nd;
    mas[dbInd] = nd;
    return dbInd++;
}
vector<int> kur;
int mx = 0;
vector<int> ans;
void add(string a, int ind, int v, int lvl) {
    if (lvl > mx) {
        mx = lvl;
        ans = kur;
    }

    kur.push_back(v);

    if (ind == a.size()) {
        mas[v].val = 1;
        kur.pop_back();
        return;
    }

    int kas = a[ind] - 'a';

    if (mas[v].nei[kas] == -1) {
        mas[v].nei[kas] = newN();
    }

    add(a, ind + 1, mas[v].nei[kas], lvl + 1);
    kur.pop_back();

}
vector<char> ats;
void dfs(int v) {
    if (mas[v].val) {
        ats.push_back('P');
    }

    bool is = 0;
    int nex = -1;
    char kas;

    for (int i = 0; i < ans.size(); i++) if (ans[i] == v) {
            is = 1;
            nex = (i == ans.size() - 1 ? -1 : ans[i + 1]);
        }

    for (int i = 0; i < 26; i++) {
        if (mas[v].nei[i] == -1) {
            continue;
        }

        if (mas[v].nei[i] == nex) {
            kas = (char)(i + 'a');
            continue;
        }

        ats.push_back((char)(i + 'a'));
        dfs(mas[v].nei[i]);
        ats.push_back('-');
    }

    if (nex != -1) {
        ats.push_back(kas);
        dfs(nex);
        ats.push_back('-');
    }
}
#include <bits/stdc++.h>
#include <unistd.h>

using namespace std;

void ___signal_handler___(int s) {
    int ignored __attribute__((unused));

    if (s == SIGSEGV) {
        ignored = write(STDOUT_FILENO, "SEGFAULT\n", 9);
    }
    else if (s == SIGFPE) {
        ignored = write(STDOUT_FILENO, "FPEXCEPTION\n", 12);
    }
    else {
        ignored = write(STDOUT_FILENO, "ABORTCLD\n", 9);
    }

    return _Exit(s);
}

[[noreturn]]void no_answer() {
    int ignored __attribute__((unused)) = write(STDOUT_FILENO, "NOANSWER\n", 9);
    exit(0);
}

int main () {
    std::ios_base::sync_with_stdio(false), std::cin.tie(0), std::cout.tie(0);
    signal(SIGSEGV, ___signal_handler___);
    signal(SIGFPE, ___signal_handler___);
    signal(SIGABRT, ___signal_handler___);

    newN();
    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        string a;
        cin >> a;
        add(a, 0, 0, 0);
    }

    dfs(0);

    while (ats.back() == '-') {
        ats.pop_back();
    }

    cout << "SUCCESS\n";
    cout << ats.size() << endl;

    for (auto x : ats) {
        cout << x << "\n";
    }





    cout << flush;
}

Compilation message

printer.cpp: In function 'void add(std::string, int, int, int)':
printer.cpp:31:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     if (ind == a.size()) {
      |         ~~~~^~~~~~~~~~~
printer.cpp: In function 'void dfs(int)':
printer.cpp:57:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for (int i = 0; i < ans.size(); i++) if (ans[i] == v) {
      |                     ~~^~~~~~~~~~~~
printer.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |             nex = (i == ans.size() - 1 ? -1 : ans[i + 1]);
      |                    ~~^~~~~~~~~~~~~~~~~
printer.cpp:53:10: warning: variable 'is' set but not used [-Wunused-but-set-variable]
   53 |     bool is = 0;
      |          ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 33 ms 53060 KB Expected integer, but "SUCCESS" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 53172 KB Expected integer, but "SUCCESS" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 34 ms 53060 KB Expected integer, but "SUCCESS" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 32 ms 53212 KB Expected integer, but "SUCCESS" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 53060 KB Expected integer, but "SUCCESS" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 53204 KB Expected integer, but "SUCCESS" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 53308 KB Expected integer, but "SUCCESS" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 53 ms 53704 KB Expected integer, but "SUCCESS" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 79 ms 54300 KB Expected integer, but "SUCCESS" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 84 ms 54032 KB Expected integer, but "SUCCESS" found
2 Halted 0 ms 0 KB -