Submission #53689

# Submission time Handle Problem Language Result Execution time Memory
53689 2018-07-01T04:45:46 Z 강한남자킹현수(#2036) Type Printer (IOI08_printer) C++11
20 / 100
72 ms 18172 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 25001;

struct Nod{
    int c[26], d;
} a[20 * N];

int n, c, v;

int g(int x){
    for(int i = 0; i < 26; i++){
        if(!a[x].c[i]) continue;
        a[x].d = max(a[x].d, g(a[x].c[i]) + 1);
    }
    return a[x].d;
}

void f(int x){
    if(!a[x].d){
        puts("P"); v--;
        return;
    }
    int p, m = -1;
    for(int i = 0; i < 26; i++){
        if(!a[x].c[i]) continue;
        if(a[a[x].c[i]].d > m){
            m = a[a[x].c[i]].d;
            p = i;
        }
    }
    for(int i = 0; i < 26; i++){
        if(i == p || !a[x].c[i]) continue;
        printf("%c\n", i + 'a'); v--;
        f(a[x].c[i]);
        puts("-"); v--;
    }
    printf("%c\n", p + 'a'); v--;
    f(a[x].c[p]);
    if(v){ puts("-"); v--; }
}

int main(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        char b[21];
        scanf("%s", b);
        for(int j = 0, t = 0; b[j]; j++){
            b[j] -= 'a';
            if(!a[t].c[b[j]]) a[t].c[b[j]] = ++c;
            t = a[t].c[b[j]];
        }
    }
    g(0);
    v = n + 2 * c - a[0].d;
    printf("%d\n", v);
    f(0);
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:51:28: warning: array subscript has type 'char' [-Wchar-subscripts]
             if(!a[t].c[b[j]]) a[t].c[b[j]] = ++c;
                            ^
printer.cpp:51:42: warning: array subscript has type 'char' [-Wchar-subscripts]
             if(!a[t].c[b[j]]) a[t].c[b[j]] = ++c;
                                          ^
printer.cpp:52:28: warning: array subscript has type 'char' [-Wchar-subscripts]
             t = a[t].c[b[j]];
                            ^
printer.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
printer.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", b);
         ~~~~~^~~~~~~~~
printer.cpp: In function 'void f(int)':
printer.cpp:34:9: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if(i == p || !a[x].c[i]) continue;
         ^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 464 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 500 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 680 KB Output is correct
2 Incorrect 2 ms 680 KB didn't print every word
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 680 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1264 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 3308 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 7548 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 72 ms 18172 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 18172 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -