회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
2
채점 현황
랭킹
게시판
그룹
더 보기
재채점 기록
블로그
강의
실험실
도움말
BOJ Stack
BOJ Book
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
시간초과가 나는데 어디가 문제일까요?? ㅜㅜ
gydbslove
4년 전
0
Travel 부분이 문제인것 같아서 vector 로 들어가야 하는 부분 인덱스 저장해서 해줬는데도 시간이 많이 걸리네요
어디가 문제인걸까요?
#include <iostream> #include <string> #include <string.h> #include <vector> using namespace std; typedef long long ll; ll dp[3001]; class Node { public: int cnt; Node *next[27]; vector <int> v; Node() { cnt = 0; memset(next,0,sizeof(next)); } }; class Tree { public: ll t; Node *head; Tree() { head = new Node(); t = 1; } void insert(Node *cur, string s, int index,int len) { if (len == index) cur->cnt++; else if (cur->next[s[index] - 65] == NULL) { cur->v.push_back(s[index] - 65); cur->next[s[index] - 65] = new Node(); cur->cnt++; insert(cur->next[s[index] - 65], s, index + 1,len); } else insert(cur->next[s[index] - 65], s, index + 1,len); } void Travel(Node *next) { if (next->cnt) { t = (t * dp[next->cnt]) % 1000000007; for (int i = 0; i < next->v.size(); i++) { Travel(next->next[next->v[i]]); } } } }; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); int n; cin >> n; Tree tree; dp[1] = 1; for (int i = 2; i <= 3000; i++) dp[i] = (dp[i - 1] * i) % 1000000007; for (int i = 0; i < n; i++) { string s; cin >> s; tree.insert(tree.head, s, 0,s.length()); } tree.Travel(tree.head); cout << tree.t << "\n"; }
댓글을 작성하려면
로그인
해야 합니다.
gydbslove 4년 전
Travel 부분이 문제인것 같아서 vector 로 들어가야 하는 부분 인덱스 저장해서 해줬는데도 시간이 많이 걸리네요
어디가 문제인걸까요?