답안 #674024

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674024 2022-12-22T15:31:16 Z peacebringer1667 Type Printer (IOI08_printer) C++17
40 / 100
1000 ms 85280 KB
#include<bits/stdc++.h>
#define whilst while
typedef long long ll;
using namespace std;
string a[25003];
int f[650078][27];
int b[25003];
int m = 0;bool eow[650078];
vector <vector<int>> vec(650078);
void dfs(int u){
	cout << (char)f[u][0] << endl;
		if (eow[u]) cout << "P" << endl; 
	for (int i = 0 ; i < vec[u].size() ; i++)
	  dfs(vec[u][i]); 
	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;
    //freopen("typ5a.in","r",stdin);
    //freopen("Warrior.txt","w",stdout);
    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++;
		}
		if (j == a[i].size()){
			j = 0;
			while (j < a[i].size()-1)
			  cur = f[cur][a[i][j]-96];j++;
			eow[cur] = 1;  
		}
		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:13:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for (int i = 0 ; i < vec[u].size() ; i++)
      |                   ~~^~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:28:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |      if (maxlen < a[i].size()){
      |          ~~~~~~~^~~~~~~~~~~~~
printer.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         while (j < a[i].size() && f[cur][a[i][j]-96]){
      |                ~~^~~~~~~~~~~~~
printer.cpp:47:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |   if (j == a[i].size()){
      |       ~~^~~~~~~~~~~~~~
printer.cpp:49:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |    while (j < a[i].size()-1)
      |           ~~^~~~~~~~~~~~~~~
printer.cpp:49:4: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   49 |    while (j < a[i].size()-1)
      |    ^~~~~
printer.cpp:50:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   50 |      cur = f[cur][a[i][j]-96];j++;
      |                               ^
printer.cpp:53:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for (int k = j ; k < a[i].size() ; k++){
      |                    ~~^~~~~~~~~~~~~
printer.cpp:60:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |  for (int i = 0 ; i < vec[0].size() ; i++) dfs(vec[0][i]);
      |                   ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 85076 KB Output is correct
2 Correct 33 ms 84964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 84964 KB Output is correct
2 Correct 33 ms 85004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 85044 KB Output is correct
2 Correct 42 ms 85008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 84964 KB Output is correct
2 Correct 34 ms 85076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 85044 KB Output is correct
2 Execution timed out 1093 ms 85136 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1080 ms 85008 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1097 ms 85072 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1099 ms 85100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1095 ms 85280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1091 ms 85076 KB Time limit exceeded
2 Halted 0 ms 0 KB -