-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
7-InSange #28
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
char str[1000001];
char ans[1000001];
char boom[37];
char last;
int ptr, len;
void Explosion() {
if (ptr <= len - 1) return;
int pos = ptr - len;
for (int i = 0; i < len; i++)
if (ans[pos + i] != boom[i]) return;
ptr = pos;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cin >> str >> boom;
len = strlen(boom);
last = boom[len - 1];
ptr = 0;
for (char c : str) {
ans[ptr++] = c;
if (c == last) Explosion();
}
ans[ptr] = '\0';
if (!strlen(ans)) printf("FRULA\n");
else printf("%s\n", ans);
}
μκ° μ μ½λ, μλκ° μ μλ μ½λμ
λλ€. λμ μΉλ¦¬!
λ―Έλ¬ν μκ°μ°¨λ stringλ char[] μ°¨μ΄μΈκ±ΈκΉμ?
λ©λͺ¨λ¦¬ μ°¨μ΄λ μ 1.5λ°° μ λ μ°¨μ΄κ° λ κΉμ? char[1000001] κ° stringλ³΄λ€ ν΄ κ±°λΌκ³ μκ°νλλ°.. ν¨μλ₯Ό μ¬μ©ν΄μ λΆκΈ°λ₯Ό μ‘°μ ν΄μ κ·Έλ°κ±ΈκΉμ? μ κΈ°λ΄κΈ°
cin.tie(nullptr);
ios::sync_with_stdio(false); μ΄κ±° λΆμ΄κΈ° μ μλ 40ms μλλ° λΆμ΄λκΉ 8msκ° λμ΄μ! input λ°λ μλλ μ°¨μ΄κ° ν¬λ€λ κ±Έ λ€μ νλ² λλΌκ³ κ°λλ€ |
stdμμ μ 곡νλ stringμ μλ‘μ΄ λ¬Έμμ΄μ΄ μΆκ°λκ±°λ λ³κ²½λμμ λ λ°°μ΄μ ν¬κΈ°λ₯Ό λ€μ ν λΉνμ§ μκΈ° μν΄ μΌλΆλ¬ μ¬λΆ 곡κ°μ λ¨κ²¨λλ΅λλ€. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
νμ΄μ¬μμλ 리μ€νΈλ‘ μ€νμ μν μ λ체νλλ° c++μμ λ¬Έμμ΄μ μ€νμΌλ‘ μΉνν΄μ ν μ μκ΅°μ. κ·Όλ° μλμ μ°¨μ΄κ° .. μμ c++ μ΄λ€μ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ€ν
μ μ°μ§μκ³ λ¬Έμμ΄
μ μ€ν
μ²λΌ νμ©ν΄μ ν μ μλ€λ...λκ² μ κΈ°νλ€μ..! λ 곡λΆν΄μΌκ² μ΅λλ€..
π λ¬Έμ λ§ν¬
λ¬Έμμ΄ νλ°
βοΈ μμλ μκ°
30λΆ
β¨ μλ μ½λ
μ²μ μ κ·Ό λ°©μ
stack
μ νμ©νμ¬ μ λ ₯λ°μ λ¨μ΄s(word)
λ₯Ό νκΈμ μ©stack
μ λ£λλ€.boom
μ λ§μ§λ§ λ¨μ΄μ μΌμΉν μμstack
μ λ€μ΄κ° λ¨μ΄λ€κ³Ό λΉκ΅νλ€. λ¨stack
μ λ€μ΄κ° λ¨μ΄ κΈΈμ΄(μ¬μ΄μ¦)κ°boom
λ¨μ΄μ κΈΈμ΄λ³΄λ€ 짧μ μ μλ΅νλ€.stack
μ μ μ₯λμ΄ μλ λ¨μ΄λ₯Ό νλμ© κΊΌλ΄λ©΄μboom
κ³Ό λΉκ΅νλ€. κΊΌλΈ λ¨μ΄λ μμstack
temp
μ 보κ΄νλ€.stack
μμ κΊΌλΈ λ¨μ΄κ°boom
κ³Ό μΌμΉνμ§ μμ κ²½μ° λ€μstack
μ λ£μ΄μ£ΌκΈ° μν¨μ΄λ€.s
μ λ§μ§λ§ λ¨μ΄κΉμ§ λ°λ³΅ν΄μ€λ€.stack
μ μμ¬μλ λ¨μ΄λ€μ λ€μμ μ°¨μ°¨ λ£μ΄μ£Όλ©΄ μ λ΅μ΄ λλ€.κ·Έλ¬λ! λ¬Έμ λ
2μ΄μ μκ°μ ν!!!
μ μ²λ¦¬κΈ° λ§λ€ μκ°μ΄ λ€ λ€λ₯΄μ§λ§
c++
μ λλ΅ 1μ΅λ²μ μ°μ°μ μννλλ° 1μ΄μ μκ°μ΄ κ±Έλ¦°λ€κ³ νλ€.첫 λ²μ§Έ νμ΄ κ³Όμ μΌλ‘ μ κ·Όνκ² λλ©΄ μ΅μ μ κ²½μ° 100λ§κ°μ λ¬Έμλ₯Ό
stack
μ λ£κ³ λΉΌκ³ λ€μ λ£κ³ λ₯Ό λ°λ³΅ν΄μΌ νλ€.stack
μ ν¬κΈ°λboom
μ κΈΈμ΄λ³΄λ€ μ»€μΌ μμ κ³Όμ μ κ±°μΉκΈ° λλ¬Έμ 10λ§κ°μ λ¨μ΄μμboom
μ μ΅κ³ κΈΈμ΄λ 36μ΄μ§λ§ 40μΌλ‘ νμΉκ² λ€. κ·ΈλΌ 99960κ°μ λ¨μ΄μμ ν λ²μ© λΉκ΅νλ κ³Όμ μ κ±°μ³μΌ νκ³ μ΅μ΅μ΅μ΅μ΅μ μ κ²½μ° 35λ²μ§Έstack
μdepth
κΉμ§ κ°λ€κ° λ§μ§λ§ ν λ¨μ΄κ°boom
μ 첫 λ²μ§Έ λ¨μ΄μ μΌμΉνμ§ μμκ²½μ° λ€μstack
μ λ£μ΄ μ£Όλ κ²½μ°λ₯Ό κ°μνμ¬36 * 35 * (1,000,000 - 40) =
μ ν¬κΈ°κ° λμ€κ² λλ€..
λλ²μ§Έ νμ΄ λ°©λ²
stack
μ μ¬μ©νκ² λλ©΄boom
κ³Ό λΉκ΅νκΈ° μν΄μ νλμ©pop
νμ¬ μ°¨λ‘μ°¨λ‘ λΉκ΅ν΄λκ°μΌ νκΈ°μstack
temp
λ₯Ό νλ μ μΈν΄μ€μ 보κ΄ν΄μ£Όλ λ°©μμ μ¬μ©νλ€.κ·Έλ¬λ λ¬Έμμ΄μ μ¬μ©νκ² λλ©΄ 맨 λ€μμ
boom
μ κΈΈμ΄λ§νΌλ§ λΉκ΅ν΄μ£Όλ©΄ λκΈ° λλ¬Έμ κ΅³μ΄pop
μ ν νμκ° μκΈ°μ μμ κ³Όμ λ€μ μλ΅ν΄μ€ μ μλ€.boom
κ³Όstack
μ΄ μΌμΉνλ©΄boom
μ κΈΈμ΄λ§νΌ λ¬Έμμ΄μ λ€μμpop
μ ν΄μ£Όλ©΄ λκ³stack
λ€μ λΆμ¬μ€λ€.μ΄λ κ² λλ©΄ λ€μ
stack
μpush
λ₯Ό ν΄μ£Όλ κ³Όμ μ΄ μλ΅λκΈ° λλ¬Έμ λλ΅36 * (1,000,000 - 40) = 35,998,560
λ§νΌμ μ°μ° μκ°μ΄ κ±Έλ¦¬κ² λλ©΄μ ν΅κ³Όν μ μλ€.
νκΈ°
μ±μμμΉκ° νΌκ²λ νμ΄μ¬μμλ μ€νμ΄λ ν μ΄λ° κ²λ€μ λͺ¨λ 리μ€νΈ(λ°°μ΄)λ‘ ν΅ν©λλ€. κ·Έλ κΈ°μ ν¬κΈ°λ§νΌ λΉκ΅ν μ μμλ κ²μ²λΌ μ°λ¦¬ C++μμλ λ¬Έμμ΄ μ체λ₯Ό μ€νμΌλ‘ μΉννμ¬ ν μ μλ€.
μ ν΅μ±μ C++, κ°λ΅ν¨μ pythonμ λΉκ΅ν΄ λ³Ό μ μμλ κ² κ°λ€.
π μλ‘κ² μκ²λ λ΄μ©
μμ νμ΄μ¬μ μ μ΄μΌ!