-
Notifications
You must be signed in to change notification settings - Fork 1
6-caucsejunseo #23
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
6-caucsejunseo #23
Conversation
|
μ λ κ° μ΅λ¬΄μμ λ§μ Python3
from collections import deque
import sys
input = sys.stdin.readline
N = int(input())
parrot = []
for _ in range(N):
tmp = deque(input().split())
parrot.append(tmp)
L = input().split()
possible = True
for word in L:
found = False
for p in parrot:
if p and p[0] == word:
p.popleft()
found = True
break
if not found:
possible = False
break
if possible:
for p in parrot:
if p:
possible = False
break
if possible:
print("Possible")
else:
print("Impossible")μ λ ₯λ°μ λ μμμΌλ‘ μ λ ¬ν΄μ μ€νμ λ£μ΄λ λ¬Έμ κ° ν릴 κ² κ°λ€μ |
hadongun
left a comment
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.
κ°κ°μ μ΅λ¬΄μκ° νλ λ§μ κ°κ° λ€λ₯Έ νμ μ μ₯νκ³ μΆμλλ°, νμ΄μ¬μ κ·Έκ² κ°λ₯νλκ΅°μ! κ°κ° Nκ°μ λ 립μ μΈ νλ₯Ό λ§λ€μ΄μ queue[i] λ₯Ό ν΅ν΄ μ κ·Όνμ¬ λΉκ΅ν΄λ΄€μ΅λλ€.
from collections import deque
import sys
def junjun():
N = int(input())
q = [deque() for _ in range(N)]
Lq = deque()
for i in range(N):
bird = []
bird = sys.stdin.readline().strip().split()
q[i] = deque(bird)
Lq = deque(sys.stdin.readline().strip().split())
gojunglength = len(Lq)
while Lq:
found = False
for j in range(N):
if q[j] and q[j][0] == Lq[0]:
q[j].popleft()
Lq.popleft()
found = True
break
if not found:
print("Impossible")
return
for i in range(N):
if q[i]:
print("Impossible")
return
print("Possible")
junjun()
dohyeondol1
left a comment
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.
μ€νΈ μ κ·Όλ³΄λ€ κ΅¬νμ΄ λ μ€μν λ¬Έμ κ°λ€μ..!
μ λ ꡬνμμ λ§νμ sstreamμ΄λΌλ λΌμ΄λΈλ¬λ¦¬λ₯Ό μ΄μ©νμ¬ ν΄κ²°νμμ΅λλ€...
sstream λΌμ΄λΈλ¬λ¦¬λ λ¬Έμμ΄μμ κ°μ μΆμΆνκ±°λ μ½μ
ν λ μ¬μ©ν©λλ€.
μ΄λ² λ¬Έμ μμλ λ¬Έμμ΄μ νμ±ν λ μ μ©νκ² μ¬μ©νμμ΅λλ€.
μ무λλ μΈμ΄μ λν μ΄ν΄μ ꡬν λ₯λ ₯μ ν€μμΌκ² μ΅λλ€.π’
C++ μ½λ
#include <iostream>
#include <sstream>
#include <string>
#include <queue>
using namespace std;
int main() {
ios::sync_with_stdio(false); cin.tie(NULL);
int N, wordCount = 0;
cin >> N;
//μ
λ ₯ ν λ¨μ λ²νΌμ κ°νλ¬Έμλ₯Ό 무μνκΈ°
cin.ignore();
queue<string> S[N];
string str, word;
for(int i = 0; i < N; i++) {
getline(cin, str);
//곡백 κΈ°μ€μΌλ‘ λ¬Έμμ΄ νμ±
stringstream stream(str);
//μ
λ ₯ μ€νΈλ¦Όμμ κ°μ μ½μ΄μ€λ μ°μ°μ '>>'
while(stream >> word) {
S[i].push(word);
wordCount++;
}
}
getline(cin, str);
stringstream stream(str);
queue<string> L;
while(stream >> word)
L.push(word);
if(L.size() != wordCount) {
cout << "Impossible" << '\n';
return 0;
}
int size = L.size();
for(int i = 0; i < size; i++) {
bool valid = false;
for(int j = 0; j < N; j++) {
if(!S[j].empty()) {
if(L.front() == S[j].front()) {
L.pop();
S[j].pop();
valid = true;
break;
}
}
}
if(!valid) {
cout << "Impossible" << '\n';
return 0;
}
}
cout << "Possible" << '\n';
return 0;
}PRμ μλ μ½λλ₯Ό μ§μ μμ±ν΄λ³΄λ κ±Έ μΆμ²λ립λλ€!
λ΄κ° μμ±ν μ½λλ₯Ό λͺ¨λ₯΄λ μ¬λμ΄ λ΄λ μ΄ν΄ν μ μλλ‘ νλ κ²μ΄ μλ μ½λ μμ±μ μ·¨μ§μ
λλ€.
λμ΄λκ° μ¬λΌκ°λ©΄, μΈμ΄μ λν μ΄ν΄κ° λΆμ‘±ν κ²½μ° μ½λλ₯Ό λͺ» μ½λ κ²½μ°λ μκΈΈ μ μκ±°λ μ.
λν μλ μ½λλ₯Ό μμ±νλ©΄μ λ³ΈμΈμ μ½λλ₯Ό λ μ μ΄ν΄ν μ μκ³ μ€λͺ
νκΈ°λ μ¬μμ§λλ€!
μ λ μλ μ½λλ₯Ό λ¨Όμ μ°κ³ PR μ€λͺ
μ μ°λ νΈμ΄μμ :)
π λ¬Έμ λ§ν¬
https://www.acmicpc.net/problem/14713
βοΈ μμλ μκ°
3h
β¨ μλ μ½λ
λ¨Όμ ꡬ쑰체λ₯Ό μ μΈν©λλ€!
ꡬ쑰체 νλκ° μ΅λ¬΄μμ λμνκ² λκ³ , ꡬ쑰체 μμ 2μ°¨μ λ°°μ΄ wordsμ νμ λ¬Έμμ΄μ λ¨μ΄ κ°μ, μ΄μ λ¬Έμμ΄μ λ¬Έμλ₯Ό μ μ₯ν©λλ€. μ¬μ€μ 3μ°¨μ λ°°μ΄μ μ¬μ©ν κ²κ³Ό κ°μ΅λλ€.

λ¬Έμμ΄μ λμ΄μ°κΈ° κΈ°μ€μΌλ‘ λλκ³ , 맨 μμ λ¨μ΄λ₯Ό enqueueνλ©° μ μ₯ν©λλ€.
μ΅λ¬΄μμ λ¬Έμμ΄μ μ λΆ μ μ₯νμμΌλ©΄ μ΄μ μ λ΅ λ¬Έμμ΄κ³Ό λΉκ΅νλ©΄ λ©λλ€.
(μ λ λ¬Έμμ΄μ μ μ₯νλ κ²μ΄ κ°μ₯ μ΄λ €μ μ΅λλ€..)
μ λ΅ λ¬Έμμ΄μ 맨 μ λ¨μ΄μ κ°κ° μ΅λ¬΄μκ° κ°μ§κ³ μλ 맨 μμ λ¨μ΄κ° μΌμΉνλ μ§λ₯Ό λΉκ΅ν©λλ€.
forλ¬Έμ λλ©° μ΅λ¬΄μμ 맨 μ λ¨μ΄μ λΉκ΅νκ³ μΌμΉνλ κ² μλ€λ©΄ κ·Έ λ¨μ΄λ₯Ό λΉΌμ£Όλ©΄ λ©λλ€.
( λ¨Όμ λ€μ΄κ° λ¬Έμκ° κ°μ₯ λ¨Όμ λμ¨λ€λ μ μμ ν! )
μ΅λ¬΄μκ° κ°μ§ λ¬Έμμ΄μ λ€ μ¬μ©νμ§ μκ³ μ λ΅ λ¬Έμμ΄μ μ°Ύμμ μλ μμΌλ―λ‘ κ·Έ λΆλΆμ μμΈμ²λ¦¬ ν΄μ€λ€λ©΄ λ!
π μλ‘κ² μκ²λ λ΄μ©
λμ΄μ°κΈ°λ₯Ό ν¬ν¨ν λ¬Έμμ΄μ λ°κΈ° μν fgets()λ₯Ό μκ² λμλ€.