STARSHIP_666's blog

By STARSHIP_666, history, 3 weeks ago, In English

Please, Can anyone tell what is my mistake in the following submission ? I am getting Unexpected EOF Error. I tried out debugging and it comes out that my code is printing 406 numbers instead of 423 but I do not understand why.

Solution link : https://mirror.codeforces.com/contest/977/submission/294164155

Source Code :

include <bits/stdc++.h>

using namespace std;

//#define int long long int //#define ull unsigned long long

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());

constexpr int V = 1E6;

void solve() { int n; cin>>n; vector v(n+1, 0); for(int i=1; i<=n; i++) cin>>v[i]; vector tracker; map<int,int> dp;

//dp[i]=length of longest sequence ending at v[i]th number

int maxi=v[1], index=0, maxdp=0;
for(int i=1; i<=n; i++)
{
    dp[v[i]]=dp[v[i]-1]+1;
}

for(auto x: dp){
    if(x.second > maxdp) {maxdp=x.second; maxi=max(maxi,x.first);}
}
cout<<maxdp<<"\n";
while(maxdp--)
    tracker.push_back(maxi--);
reverse(tracker.begin(), tracker.end());
auto it=tracker.begin();
for(int i=1; i<=n; i++)
{
    if(v[i]==*it)
    {
        cout<<i<<" ";
        it++;
    }
    if(it==tracker.end())
        break;
}
cout<<"\n";

}

int32_t main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); auto begin = std::chrono::high_resolution_clock::now(); int t; t=1;

while (t--) 
{
    solve();
}
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n";
return 0;

}

Full text and comments »

  • Vote: I like it
  • 0
  • Vote: I do not like it