Submission #675806

# Submission time Handle Problem Language Result Execution time Memory
675806 2022-12-28T01:52:24 Z Cookie Type Printer (IOI08_printer) C++14
20 / 100
38 ms 17680 KB
#include<bits/stdc++.h>

#include<fstream>

using namespace std;
ifstream fin("inpppp.txt");
ofstream fout("outt.txt");
#define ll long long
#define vt vector
#define pb push_back
#define fi first
#define se second
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
//#define int long long
typedef unsigned long long ull;
const int mxn = 2e4;

const ll p[4] = {2, 3, 5, 7};
int n, mx = 0, t = 0;
string no;
struct th{
    int nxt[26] = {};
};
vt<char>res;
th trie[mxn * 21];
bool spe[mxn * 21];
void add(string s){
    int nd = 0;
    for(int i = 0; i < s.size(); i++){
        int c = s[i] - 'a';
        if(trie[nd].nxt[c] == 0)trie[nd].nxt[c] = ++t;
        nd = trie[nd].nxt[c];
    }
}
void find(string s){
    int nd  =0;
    for(int i = 0; i < s.size(); i++){
        int c = s[i] - 'a';
        if(trie[nd].nxt[c] == 0)trie[nd].nxt[c] = ++t;
        nd = trie[nd].nxt[c]; spe[nd] = true;
    }
}
void dfs(int s){
    bool leaf = true;
    for(int i = 0; i < 26; i++){
        int v = trie[s].nxt[i];
        if(!spe[v] && v){
            leaf = false;
            res.pb((char)(i + 'a'));
            dfs(v);
        }
    }
    for(int i = 0; i < 26; i++){
        int v = trie[s].nxt[i];
        if(spe[v] && v){
            leaf = false;
            res.pb((char)(i + 'a'));
            dfs(v);
        }
    }
    if(leaf)res.pb('P');
    if(!spe[s])res.pb('-');
}
signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    spe[0] = true;
    forr(i, 0, n){
        string s; cin >> s; 
        add(s);
        if(s.size() > mx){
            mx = s.size(); no = s;
        }
    }
    find(no);
    dfs(0);
    cout << res.size() << "\n";
    for(auto i: res)cout << i << "\n";
    return 0;
}

Compilation message

printer.cpp: In function 'void add(std::string)':
printer.cpp:32:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
printer.cpp: In function 'void find(std::string)':
printer.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:75:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   75 |         if(s.size() > mx){
      |            ~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB didn't print every word
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 340 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 980 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 3028 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 7276 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 17680 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 13844 KB didn't print every word
2 Halted 0 ms 0 KB -