竹園論壇

標題: [求救] poj 3320 [打印本頁]

作者: domen111    時間: 2014-8-12 18:10
標題: [求救] poj 3320
本帖最後由 domen111 於 2014-8-12 20:23 編輯

爬行法的題目,這題用map解應該沒錯啊! O(nlgn)為什麼會TLE?

[C++] 純文本查看 復制代碼
#include<iostream>
#include<map>
#include<climits>
#include<algorithm>
#include<set>
using namespace std;
int a[1000010];
int main()
{
        int p;
        cin>>p;
        for(int i=0;i<p;i++)
                cin>>a;

        set<int> couse;
        for(int i=0;i<p;i++)
                couse.insert(a);
        int cc=couse.size(); //couse count

        map<int,int> c;
        int s=0,t=0;
        int ans=INT_MAX;
        while(t<=p)
        {
                if(c.size()>=cc)
                {
                        ans=min(ans,t-s);
                        c[a]--;
                        if(c[a]==0)
                                c.erase(a);
                        s++;
                }
                else
                {
                        c[a[t]]++;
                        t++;
                }
        }
        cout<<ans<<endl;
}


作者: Sylveon    時間: 2014-8-12 19:08
先把cin/cout改掉再討論。都跟你們說io速度差很多都不聽
作者: allenwhale    時間: 2014-8-12 19:12
速度可以差到一倍以上...
作者: amoshuangyc    時間: 2014-8-12 21:52
或者將 ios::sync_with_stdio(false); 加在 main 的第一行。




歡迎光臨 竹園論壇 (http://forum.tfcis.org/) Powered by Discuz! X3.2