답안 #305377

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
305377 2020-09-23T02:01:05 Z FlashGamezzz Rima (COCI17_rima) C++17
70 / 140
305 ms 65912 KB
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <queue>
 
using namespace std;
 
bool endw[3000000] = {};
int lets[3000000][26] = {}, dp[3000000] = {}, sz = 1, ans = 0;
string s;
 
void add(int c, int i){
	if (i == s.length()){
		endw[c] = true; return;
	}
	int l = int(s[s.length()-i-1])-97;
	if (lets[c][l] == 0){
		lets[c][l] = sz; sz++;
	}
	add(lets[c][l], i+1);
}
void solve(int c){
	vector<int> vals;
	for (int i = 0; i < 26; i++){
		if (lets[c][i] > 0){
			solve(lets[c][i]);
			if (endw[lets[c][i]]){
				dp[c]++;
				vals.push_back(dp[lets[c][i]]);
			}
		}
	}
	sort(vals.begin(), vals.end());
	if (vals.size() >= 1){
		dp[c] += vals[vals.size()-1];
	}
	if (vals.size() >= 2){
		ans = max(ans, dp[c] + vals[vals.size()-2]);
	}
	ans = max(ans, dp[c]);
}
 
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	for (int i = 0; i < n; i++){
		cin >> s; add(0, 0);
	}
	solve(0);
	cout << ans << endl;
}

Compilation message

rima.cpp: In function 'void add(int, int)':
rima.cpp:18:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  if (i == s.length()){
      |      ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 305 ms 65912 KB Output is correct
5 Correct 18 ms 768 KB Output is correct
6 Incorrect 57 ms 55044 KB Output isn't correct
7 Incorrect 61 ms 55064 KB Output isn't correct
8 Incorrect 57 ms 55132 KB Output isn't correct
9 Incorrect 79 ms 56404 KB Output isn't correct
10 Incorrect 57 ms 54908 KB Output isn't correct