Submission #953531

# Submission time Handle Problem Language Result Execution time Memory
953531 2024-03-26T05:35:43 Z DarkKnight101 Type Printer (IOI08_printer) C++17
10 / 100
870 ms 97532 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
 
#define endl "\n"
#define aint(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define forl(i,n) for(int i=0;i<n;i++)

const ll WMAX = 5e5+5;
const ll MOD = 1e9 + 7;

ll trie[WMAX][26];
ll node_count;
bool stop[WMAX];

/** Adds a new word into the trie. */
void insert_word(string& word) {
	// Node 0 has 26 children - a through z.
	ll node = 0;
	for (char c : word) {
		// If a node with the current char doesn't exist create one.
		if (trie[node][c - 'a'] == 0) { trie[node][c - 'a'] = ++node_count; }
		// Move down the path in the trie.
		node = trie[node][c - 'a'];
	}
	// Mark the ending node so we know it's a dictionary word
	stop[node] = true;
}

vector<vector<char> > ans(26);


void fun(ll node,ll curr){
    forl(i,26){
        if(trie[node][(i+curr)%26]){
            ans[curr].pb(97+(i+curr)%26);
            
            if(stop[trie[node][(i+curr)%26]]) {
                ans[curr].pb('P');
            }
            
            fun(trie[node][(i+curr)%26],curr);
            ans[curr].pb(45);
        }
    }
}

void solve(){
    ll n;
    cin >> n;
    string s;
    forl(i,n){
        cin >> s;
        insert_word(s);
    }
    forl(i,26){
        fun(0,i);
        while(ans[i].back()=='-') ans[i].pop_back();
    }
    ll mn = LLONG_MAX, ind = 0;
    forl(i,26){
        if(ans[i].size()<mn){
            mn = ans[i].size();
            ind = i;
        }   
    }
    cout << mn << endl;
    for(auto i:ans[ind]) cout << i << endl;


}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt=1;
    // cin >> tt;
    while (tt--){
        solve();
    }
}

Compilation message

printer.cpp: In function 'void solve()':
printer.cpp:67:25: warning: comparison of integer expressions of different signedness: 'std::vector<char>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   67 |         if(ans[i].size()<mn){
      |            ~~~~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 2140 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 6988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 147 ms 17400 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 412 ms 42764 KB Output is correct
2 Correct 870 ms 97532 KB Output is correct
3 Incorrect 453 ms 50360 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 347 ms 33564 KB Output isn't correct
2 Halted 0 ms 0 KB -