본문 바로가기
알고리즘

[C++] 실행 속도 높이기 (ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); endl)

by jsh5408 2022. 3. 11.

C++ 로 알고리즘 문제 풀 때 유용한 실행 속도 높이는 방법들

 

 

cin, cout 이용 시,

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    ...
    
    return 0;
}

처럼

 

main 상단에 아래 코드 추가

ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);

 

 

또한 개행 문자는 endl 보다 "\n" 이용하기

cout << "hello world" << endl;

cout << "hello world" << "\n";

 

* 주의) 이 때, scanf, printf, ... C언어의 입출력 함수 사용하면 안된다

(cin, cout 과 scanf, printf, ... 를 섞어 쓰지 말 것)

 

 

 

그 외에도

전역 변수 사용하기,

메모리풀 이용

등이 있다.

 

댓글