https://www.acmicpc.net/problem/10989
첫번째엔 sort함수 썼다가 메모리초과,
두번째엔 2중 for문 때문에 시간초과.
어떻게 하지 하고 구글링하다가 나랑 정말 똑같이 접근한 분을 찾았다.
여기! https://tooo1.tistory.com/72
그런데 나는 다음 코드를 추가해도 여전히 시간초과였다.
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
아니 진짜... 왜지? 저분이랑 똑같은데.
endl 말고 "\n"을 써야 한다고 한다.
찾아보니, endl은 출력버퍼를 비우는 거라 느리다고.
(https://dbstndi6316.tistory.com/267)
#include <iostream>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N; cin >> N;
int arr[10001] = { 0 }; //i의 개수
int input;
for (int n = 0; n < N; n++) { //N번 반복
cin >> input;
arr[input]++;
}
for (int i = 1; i < 10001; i++) //i = 10,000보다 작거나 같은 자연수
for (int n = 0; n < arr[i]; n++) //i를 arr[i]번 출력
cout << i << "\n"; //여기 endl로 쓰면 시간초과가 뜬다.
return 0;
}