답안 #737942

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
737942 2023-05-08T02:48:38 Z guagua0407 Type Printer (IOI08_printer) C++17
20 / 100
46 ms 52632 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

const int mxn=2.5e4*20+5;
int trie[mxn][26];
char c[mxn];
int cur=1;
vector<char> ans;
string mx="";

void dfs(int v,int d=0,bool tf=true){
    if(v!=0) ans.push_back(c[v]);
    int cnt=0;
    for(int i=0;i<26;i++){
        if(trie[v][i]!=-1){
            cnt++;
            if(tf and d<mx.length() and (mx[d]-'a')==i) continue;
            dfs(trie[v][i],d+1,false);
        }
    }
    if(tf and d<mx.length()){
        dfs(trie[v][mx[d]-'a'],d+1,true);
    }
    if(cnt==0) ans.push_back('P');
    if(v!=0) ans.push_back('-');
}

void insert(string str){
    int v=0,i=0;
    while(i<str.length()){
        if(trie[v][str[i]-'a']==-1){
            trie[v][str[i]-'a']=cur;
            v=cur;
            c[cur]=str[i];
            cur++;
        }
        else{
            v=trie[v][str[i]-'a'];
        }
        i++;
    }
}

int main() {_
    for(int i=0;i<mxn;i++){
        for(int j=0;j<26;j++){
            trie[i][j]=-1;
        }
    }
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string str;
        cin>>str;
        insert(str);
        if(str.length()>mx.length()){
            mx=str;
        }
    }
    dfs(0);
    while(ans.back()=='-') ans.pop_back();
    cout<<(int)ans.size()<<'\n';
    for(auto v:ans){
        cout<<v<<'\n';
    }
    return 0;
}
//maybe its multiset not set

Compilation message

printer.cpp: In function 'void dfs(int, int, bool)':
printer.cpp:29:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |             if(tf and d<mx.length() and (mx[d]-'a')==i) continue;
      |                       ~^~~~~~~~~~~~
printer.cpp:33:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     if(tf and d<mx.length()){
      |               ~^~~~~~~~~~~~
printer.cpp: In function 'void insert(std::string)':
printer.cpp:42:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     while(i<str.length()){
      |           ~^~~~~~~~~~~~~
printer.cpp: In function 'void setIO(std::string)':
printer.cpp:12:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 51160 KB Output is correct
2 Correct 19 ms 51196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 51204 KB Output is correct
2 Correct 20 ms 51156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 51176 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 51276 KB Output is correct
2 Incorrect 23 ms 51148 KB didn't print every word
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 51156 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 20 ms 51284 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 51472 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 51780 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 46 ms 52632 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 52352 KB didn't print every word
2 Halted 0 ms 0 KB -