Saleh127

UVA 10176

Jun 25th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define test int t; cin>>t; while (t--)
  4. #define ll long long int
  5. ll mod(ll a,ll c,ll m)
  6. {
  7. if(c==0) return 1;
  8. ll x=mod(a,c/2,m);
  9. x=(x*x)%m;
  10. if(c%2==1)
  11. {
  12. x=(x*a)%m;
  13. }
  14. return x;
  15. }
  16. int main()
  17. {
  18. char ch;
  19. string s="";
  20. while(cin>>ch)
  21. {
  22. if(ch!='#')
  23. {
  24. s+=ch;
  25. continue;
  26. }
  27. ll l=s.size();
  28. l--;
  29. ll ans=0;
  30. for(ll i=0; i<s.size(); i++)
  31. {
  32. if(s[i]=='0') continue;
  33. else
  34. {
  35. ans=(ans+mod(2,l,131071))%131071;
  36. l--;
  37. }
  38. }
  39. if(ans==0) cout<<"YES\n";
  40. else cout<<"NO\n";
  41. s="";
  42. }
  43. return 0;
  44. }
  45. /* others solution
  46. int main()
  47. {
  48. ///freopen("input.txt","r",stdin);
  49. ///freopen("output.txt","w",stdout);
  50. char ch;
  51. int num=131071, n=0;
  52. while((ch=getchar()) !=EOF)
  53. {
  54. if(ch=='#')
  55. {
  56. if(n==0)
  57. cout<<"YES"<<endl;
  58. else
  59. cout<<"NO"<<endl;
  60. n=0;
  61. }
  62. else
  63. {
  64. if(ch!='\n')
  65. n=(n*2+ch-48)%num;
  66. }
  67. }
  68. return 0;
  69. }*/
Advertisement
Add Comment
Please, Sign In to add comment