Submission #53690

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

const int N = 25001;

struct Nod{
    int c[26], d, p;
} 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;
    }
    if(a[x].p){ puts("P"); v--; }
    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);
        int t = 0;
        for(int j = 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]];
        }
        a[t].p = 1;
    }
    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:53:28: warning: array subscript has type 'char' [-Wchar-subscripts]
             if(!a[t].c[b[j]]) a[t].c[b[j]] = ++c;
                            ^
printer.cpp:53:42: warning: array subscript has type 'char' [-Wchar-subscripts]
             if(!a[t].c[b[j]]) a[t].c[b[j]] = ++c;
                                          ^
printer.cpp:54:28: warning: array subscript has type 'char' [-Wchar-subscripts]
             t = a[t].c[b[j]];
                            ^
printer.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
printer.cpp:49: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:35: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 2 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 544 KB Output is correct
2 Correct 3 ms 544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 544 KB Output is correct
2 Correct 2 ms 544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 544 KB Output is correct
2 Correct 2 ms 544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 544 KB Output is correct
2 Correct 3 ms 928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1312 KB Output is correct
2 Correct 6 ms 1532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3324 KB Output is correct
2 Correct 30 ms 6652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 7948 KB Output is correct
2 Correct 12 ms 7948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 83 ms 18732 KB Output is correct
2 Correct 155 ms 42464 KB Output is correct
3 Correct 83 ms 42464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 42464 KB Output is correct
2 Correct 229 ms 50420 KB Output is correct
3 Correct 91 ms 50420 KB Output is correct
4 Correct 159 ms 50420 KB Output is correct