Submission #582389

# Submission time Handle Problem Language Result Execution time Memory
582389 2022-06-23T17:14:48 Z mohammad_kilani Type Printer (IOI08_printer) C++17
100 / 100
64 ms 59228 KB
#include <bits/stdc++.h>
using namespace std;
#define oo 1000000010
#define mod 998244353
const int N = 25000;
const int M = N * 20 + 1;

int T[M][26] , nodeCnt = 1;

pair< int , int > lastCharacter[M];

bool shouldBePrinted[M];

void insert(string &s){
	int node = 0;
	for(int i = 0;i < (int)s.size();i++){
		if((int)s.size() > lastCharacter[node].first){
			lastCharacter[node] = make_pair((int)s.size() , s[i] - 'a');
		}
		if(T[node][s[i] - 'a'] == -1){
			lastCharacter[nodeCnt] = make_pair(-oo , -1);
			T[node][s[i] - 'a'] = nodeCnt++;
		}
		node = T[node][s[i] - 'a'];
	}
	shouldBePrinted[node] = true;
}

string ans;

void DFS(int node,bool erja3){
	if(shouldBePrinted[node]){
		ans += 'P';
		ans += '\n';
	}
	for(int i = 0;i < 26;i++){
		if(T[node][i] != -1 && i != lastCharacter[node].second){
			ans += (char)(i + 'a');
			ans += '\n';
			DFS(T[node][i] , true);

			ans += '-';
			ans += '\n';
		}
	}
	
	if(lastCharacter[node].second != -1){
		ans += (lastCharacter[node].second + 'a');
		ans += '\n';
		DFS(T[node][lastCharacter[node].second] , erja3);
		if(erja3){
			ans += '-';
			ans += '\n';
		}

	}


}


int main(){
	memset(T,-1,sizeof(T));
	lastCharacter[0] = make_pair(-oo , -1);

	int n;
	scanf("%d",&n);
	char tmpRead[21];
	string s;
	for(int i = 0 ;i < n;i++){
		scanf("%s",tmpRead);
		s = (string)tmpRead;
		insert(s);
	}
	DFS(0 , false);

	cout << (int)ans.size() / 2 << endl;
	printf("%s",ans.c_str());
    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:67:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
printer.cpp:71:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |   scanf("%s",tmpRead);
      |   ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 20 ms 51156 KB Output is correct
2 Correct 21 ms 51208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 51116 KB Output is correct
2 Correct 21 ms 51144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 51136 KB Output is correct
2 Correct 22 ms 51192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 51156 KB Output is correct
2 Correct 23 ms 51200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 51188 KB Output is correct
2 Correct 22 ms 51268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 51312 KB Output is correct
2 Correct 23 ms 51360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 51656 KB Output is correct
2 Correct 26 ms 52232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 52460 KB Output is correct
2 Correct 28 ms 51760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 54152 KB Output is correct
2 Correct 56 ms 57920 KB Output is correct
3 Correct 42 ms 54920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 53620 KB Output is correct
2 Correct 64 ms 59228 KB Output is correct
3 Correct 55 ms 55448 KB Output is correct
4 Correct 60 ms 58816 KB Output is correct