9度cin/cout消費時間の原因


9度の問題をする時、データ量が大きいため、多くの場合cinとcoutの代わりにscanfとprintfを使って入出力に使わなければならなくて、さもなくばタイムアウトを報告してACができないことができます.
C++の入出力速度を向上させるには、次の3つの推奨事項があります.
  • At the first line in main function,add :std::ios_base::sync_with_stdio(false).which cancel theSynchronization between and ;
  • At the second line in main function,add: std::cin.tie(0).which leads to that cin ties nothing.cin ties cout at first.
  • For all endl, use '' or""instead.
  • #include<algorithm>  
    #include<cstring>  
    using namespace std;  
    int main()  
    {  
        std::ios::sync_with_stdio(false);  
        cin.tie(0);  
        int n,m;  
        cin>>n>>m;  
        cout<<n<<" "<<m<<"
    "; return 0; }