fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define SI1(v) scanf("%d",&v) // int 1
  4. #define SI2(v1,v2) scanf("%d%d",&v1,&v2) // int 2
  5. #define SI3(v1,v2,v3) scanf("%d%d%d",&v1,&v2,&v3) // int 3
  6. #define SLL1(v) scanf("%lld",&v) // long long 1
  7. #define SLL2(v1,v2) scanf("%lld%lld",&v1,&v2) // long long 2
  8. #define PI1(v) printf("%d\n",v) // int 1
  9. #define PI2(v1,v2) printf("%d %d\n",v1,v2) // int 2
  10. #define PLL1(v) printf("%lld\n",v) // long long 1
  11. #define Line printf("\n");
  12. typedef long long ll;
  13. vector<ll>V;
  14. map<string,int>M;
  15. bool vis[20];
  16. void solve(string s,ll c,int l)
  17. {
  18. if(s[0]=='0')return;
  19. ll v =stoi(s);
  20. if(v%5==0)
  21. {
  22. V.push_back(c);
  23. return;
  24. }
  25.  
  26. for(int i=0; i<s.size()-1; i++)
  27. {
  28. if(i == l ) continue;
  29. swap(s[i],s[i+1]);
  30. //cout<<s<<endl;
  31. solve(s,c+1,i);
  32. swap(s[i],s[i+1]);
  33. }
  34.  
  35. }
  36. int main()
  37. {
  38. // freopen("read.txt","r",stdin);
  39. string n;
  40. cin>>(n);
  41.  
  42. solve(n,0,-1);
  43. if(V.size())
  44. {
  45. sort(V.begin(),V.end());
  46. PLL1(V[V.size()-1]);
  47. }
  48. else
  49. PI1(-1);
  50. }
  51.  
Runtime error #stdin #stdout #stderr 0s 4292KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::invalid_argument'
  what():  stoi