Submission #674010

# Submission time Handle Problem Language Result Execution time Memory
674010 2022-12-22T14:39:35 Z peacebringer1667 Type Printer (IOI08_printer) C++17
20 / 100
61 ms 10580 KB
#include<bits/stdc++.h>
#define whilst while
typedef long long ll;
using namespace std;
string a[25003];
int f[25003][27];
int b[25003];
int m = 0;bool eow[25003];
vector <vector<int>> vec(25006);
void dfs(int u){
	cout << (char)f[u][0] << endl;
	for (int i = 0 ; i < vec[u].size() ; i++)
	  dfs(vec[u][i]);
	if (eow[u]) cout << "P" << endl;  
	if (u == m) m = -1;
	if (m != -1) cout << "-" << endl; 
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
    int d1 = 0,n,cur,j,maxlen = 0,index = n;string x;
    cin >> n;
    memset(f,0,sizeof(f));
    for (int i = 1 ; i <= n ; i++){
    	cin >> a[i];
    	if (maxlen < a[i].size()){
    		maxlen = a[i].size();index = i;
		}
	}
	swap(a[index],a[n]);
	for (int i = 1 ; i < n ; i++) 
	  if (a[i][0] == a[n][0]){
		d1++;b[d1] = i;
	}int d2 = d1;d1 = 1;
	for (int i = n-1 ; i >= n-d2 ; i--)
	  if (a[i][0] != a[n][0]){
	  	  swap(a[i],a[b[d1]]);
	  	  d1++;
	  }
	for (int i = 1 ; i <= n; i++){
    	cur = 0,j = 0;
        while (j < a[i].size() && f[cur][a[i][j]-96]){
        	cur = f[cur][a[i][j]-96];j++;
		}
		for (int k = j ; k < a[i].size() ; k++){
			m++;f[cur][a[i][k]-96] = m;f[m][0] = a[i][k];vec[cur].push_back(m);
			cur = m;
		}
		eow[m] = 1;
	}
		cout << 2*m - a[n].size() + n<< endl;
	for (int i = 0 ; i < vec[0].size() ; i++) dfs(vec[0][i]);
	return 0;
}

Compilation message

printer.cpp: In function 'void dfs(int)':
printer.cpp:12:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |  for (int i = 0 ; i < vec[u].size() ; i++)
      |                   ~~^~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:26:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |      if (maxlen < a[i].size()){
      |          ~~~~~~~^~~~~~~~~~~~~
printer.cpp:42:18: 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 (j < a[i].size() && f[cur][a[i][j]-96]){
      |                ~~^~~~~~~~~~~~~
printer.cpp:45:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for (int k = j ; k < a[i].size() ; k++){
      |                    ~~^~~~~~~~~~~~~
printer.cpp:52:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for (int i = 0 ; i < vec[0].size() ; i++) dfs(vec[0][i]);
      |                   ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4308 KB Output is correct
2 Correct 2 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4308 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4308 KB Output is correct
2 Incorrect 2 ms 4308 KB printed invalid word
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4308 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 4580 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 61 ms 5172 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 10068 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 10580 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 9940 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -