Submission #1016600

# Submission time Handle Problem Language Result Execution time Memory
1016600 2024-07-08T08:46:01 Z NintsiChkhaidze Type Printer (IOI08_printer) C++17
10 / 100
236 ms 30928 KB
#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define pb push_back
#define pii pair <int,int>
#define ll long long
#define left h*2,l,(l + r)/2
#define right h*2+1,(l + r)/2 + 1,r
// #define int ll
using namespace std;

const int N = 3e5 + 5;

int lenmx,cnt = 1;
int t[500005][30],fin[500005];
string s[N],str;
vector <char> ans;

void add(string x){
	int root = 1;

	for (int i = 0; i < x.size(); i++){
		int b = (x[i] - 'a' + 1);
		if (!t[root][b]){
			t[root][b] = ++cnt;
		}

		root = t[root][b];
	}
	fin[root] = 1;
}

void dfs(int x,int i,bool eq){

	if (fin[x]) ans.pb('P');
	if (eq == 1 && i == str.size()) {
		cout<<ans.size()<<endl;
		for (auto c: ans)
			cout<<c<<endl;
		exit(0);
	}

	int b = (str[i] - 'a' + 1);
	for (int j = 1; j <= 26; j++){
		if (!t[x][j]) continue;
		if (j != b){
			ans.pb(char(j + 'a' - 1));
			dfs(t[x][j],i + 1,0);
		}else if (eq) continue;	
	}

	if (eq) {
		ans.pb(char(b + 'a' - 1));
		dfs(t[x][b],i + 1,1);
	}

	ans.pb('-');
}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);

	int n;
	cin>>n;

	for (int i = 1; i <= n; i++){
		cin >> s[i];
		add(s[i]);
		int len = s[i].size();
		if (len > lenmx){
			str = s[i];
			lenmx = len;
		}
	}

	dfs(1,0,1);
}

Compilation message

printer.cpp: In function 'void add(std::string)':
printer.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  for (int i = 0; i < x.size(); i++){
      |                  ~~^~~~~~~~~~
printer.cpp: In function 'void dfs(int, int, bool)':
printer.cpp:37:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  if (eq == 1 && i == str.size()) {
      |                 ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 2 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 10844 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 10840 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 10844 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 10840 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 11608 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 13916 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 112 ms 18716 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 236 ms 30928 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 231 ms 26348 KB didn't print every word
2 Halted 0 ms 0 KB -