답안 #551254

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551254 2022-04-20T07:04:05 Z ToroTN Type Printer (IOI08_printer) C++14
40 / 100
170 ms 262144 KB
#include<bits/stdc++.h>
using namespace std;
int t,trie[500005][27],n,node,cnt=0,hsh[500005],mx=-1,print=0;
char s[25],phero[25];
vector<char> krit;
void dfs(int u,int lv)
{
    if(hsh[u]!=0)
    {
        krit.push_back('P');
        ++print;
    }
    for(int i=0;i<26;i++)
    {
        if('a'+i!=phero[lv])
        if(trie[u][i]!=-1)
        {
            krit.push_back('a'+i);
            dfs(trie[u][i],lv+1);
            if(print!=t)
            krit.push_back('-');
        }
    }
    if(trie[u][phero[lv]-'a']!=-1)
    {
        krit.push_back(phero[lv]);
        dfs(trie[u][phero[lv]-'a'],lv+1);
        if(print!=t)
        krit.push_back('-');
    }
}
int main()
{
    memset(trie,-1,sizeof trie);
    scanf("%d",&t);
    for(int j=1;j<=t;j++)
    {
        scanf("%s",s+1);
        n=0;
        for(int i=1;s[i];i++)++n;
        node=0;
        for(int i=1;i<=n;i++)
        {
            if(trie[node][s[i]-'a']==-1)
            {
                ++cnt;
                trie[node][s[i]-'a']=cnt;
            }
            node=trie[node][s[i]-'a'];
        }
        hsh[node]=j;
        if(n>mx)
        {
            mx=n;
            for(int i=1;i<=n;i++)phero[i]=s[i];
        }
    }
    dfs(0,1);
    printf("%d\n",krit.size());
    for(int i=0;i<krit.size();i++)
    {
        printf("%c\n",krit[i]);
    }
}
/*
3
print
the
poem
*/

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:59:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wformat=]
   59 |     printf("%d\n",krit.size());
      |             ~^    ~~~~~~~~~~~
      |              |             |
      |              int           std::vector<char>::size_type {aka long unsigned int}
      |             %ld
printer.cpp:60:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for(int i=0;i<krit.size();i++)
      |                 ~^~~~~~~~~~~~
printer.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     scanf("%d",&t);
      |     ~~~~~^~~~~~~~~
printer.cpp:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf("%s",s+1);
      |         ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 53076 KB Output is correct
2 Runtime error 170 ms 262144 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 53144 KB Output is correct
2 Correct 21 ms 53100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 53044 KB Output is correct
2 Correct 21 ms 53124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 53080 KB Output is correct
2 Correct 20 ms 53076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 53244 KB Output is correct
2 Incorrect 21 ms 53152 KB Line "
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 53224 KB Output is correct
2 Correct 21 ms 53200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 53460 KB Line "
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 53960 KB Output is correct
2 Incorrect 27 ms 53424 KB Line "
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 52 ms 55008 KB Line "
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 71 ms 54680 KB Output is correct
2 Incorrect 107 ms 57864 KB Line "
3 Halted 0 ms 0 KB -