on
[211103] BOJ 10816 숫자 카드 2 실패기록
[211103] BOJ 10816 숫자 카드 2 실패기록
그래 역시 실패는 성공의 어쩔티비다.
첫트. 누가봐도 메모리 초과하게 생겼음
그럼에도 구현을 해본 이유는? (몰라 심심한가보지)
//숫자 카드2 https://www.acmicpc.net/problem/10816 #include using namespace std; int pos[10000001], neg[100000001]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int n, m, tmp; cin >> n; for(int i=0; i> tmp; if(tmp<0) neg[-tmp]++; else pos[tmp]++; } cin >> m; for(int i=0; i> tmp; if(tmp<0) cout << neg[-tmp] << " "; else cout << pos[tmp] << " "; } cout << endl; return 0; }
전에 푼 중복 빼고 정렬하기는 저따구로 해도 풀렸음 (물론 -1000 ~ 1000 였음 ㅋㅋ;;)
둘째트. 뭘한건지 몰겠는데 구현을 해보았습니다.
하면서도 시간초과나게 생겼구만^^ 하면서 풀어보는 이유는? (몰ㄹ ㅏ시간많은가보지)
//숫자 카드2 https://www.acmicpc.net/problem/10816 #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int n, m, tmp, count=0; vector > card; cin >> n; for(int i=0; i> tmp; bool flag = false; for(int j=0; j> m; for(int i=0; i> tmp; bool flag = false; for(int i=0; i
방황하는 sort여~ 거기 왜 있는건지?ㅎㅎ;;
배운 것이 생각나지 않습니다 ^^ 이 길은 제 길이 아닌걸까요?
두번했으면 많이했다.. 구굴링을 통해 그들의 해답을 결국 보고 맙니다
그리고 드는 생각은
역시 실패는 성공의 어쩔티비야..
1. upper_bound, low_bound를 이용한 풀이
//숫자 카드2 https://www.acmicpc.net/problem/10816 #include #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int n, m; cin >> n; vector card(n); for(int i=0; i> card[i]; sort(card.begin(), card.end()); cin >> m; vector pick(m); for(int i=0; i> tmp; auto upper = upper_bound(card.begin(), card.end(), tmp); auto lower = lower_bound(card.begin(), card.end(), tmp); pick[i] = upper - lower; } for(auto n : pick) cout << n << " "; cout << endl; return 0; }
2. 해시맵을 이용한 풀이
//숫자 카드2 https://www.acmicpc.net/problem/10816 #include #include using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); int n, m, tmp; unordered_map map; cin >> n; for(int i=0; i> tmp; map[tmp]++; } cin >> m; for(int i=0; i> tmp; cout << map[tmp] << " "; } cout << endl; return 0; }
[참고]
from http://flpdsc.tistory.com/181 by ccl(A) rewrite - 2021-11-03 20:26:50