fork download
  1. #include<stdio.h>
  2. #include<vector>
  3. #include<algorithm>
  4. #include<iostream>
  5. typedef long long ll;
  6. int main()
  7. {
  8. using namespace std;
  9. vector<ll> ar;
  10. using namespace std;
  11. ll t,i,k;
  12. ar.push_back(0);
  13. for(i=1;i<=500000;i++)
  14. {
  15. k=ar[i-1]-i;
  16. if((ar[i-1]-i)>0 && find(ar.begin(),ar.end(),k)==ar.end())
  17. ar.push_back(ar[i-1]-i);
  18. else
  19. ar.push_back(ar[i-1]+i);
  20. }
  21. while(scanf("%lld",&t)==1)
  22. {
  23. if(t==-1)
  24. break;
  25. printf("%lld\n",ar[t]);
  26. }
  27. return 0;
  28. }
Time limit exceeded #stdin #stdout 5s 4480KB
stdin
7
-1
stdout
Standard output is empty