fork download
  1. #include<bits/stdc++.h>
  2. #define faster ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  3. #define db double
  4. #define bo bool
  5. #define vo void
  6. #define ch char
  7. #define fl float
  8. #define ll long long
  9. #define ull unsigned long long
  10. #define str string
  11. #define re return
  12. #define all(x) (x).begin(),(x).end()
  13. using namespace std;
  14. //ĐỀ THI TUYỂN SINH VÀO LỚP 10 THPT CHUYÊN HÀ TĨNH
  15. vo bai1()
  16. {
  17. ll k;
  18. cin>>k;
  19. cout<<k*k-1;
  20. }
  21. bo ok(ll n)
  22. {
  23. if(n<2) re 0;
  24. if(n<=3) re 1;
  25. if(n%2==0||n%3==0) re 0;
  26. for(ll i=5;i<=sqrt(n);i+=6) if(n%i==0||n%(i+2)==0) re 0;
  27. re 1;
  28. }
  29. vo bai2()
  30. {
  31. ll t=0;
  32. str n;
  33. cin>>n;
  34. for(ch c:n) t+=pow(c-'0',2);
  35. cout<<(ok(t)?1:-1)<<"\n"<<t;
  36. }
  37. vo bai3()
  38. {
  39. ll n,i,d=1,res=0;
  40. cin>>n;
  41. vector<ll> a(n);
  42. for(auto &i:a) cin>>i;
  43. for(i=1;i<n;i++)
  44. {
  45. if(a[i]*a[i-1]>0) d++;
  46. else
  47. {
  48. res=max(res,d);
  49. d=1;
  50. }
  51. }
  52. cout<<max(res,d);
  53. }
  54. vo bai4()
  55. {
  56. ll n,i,dem[4]={0,0,0,0},sl=3,res=LLONG_MAX,l=0,r;
  57. cin>>n;
  58. vector<pair<ll,ll>> a(n);
  59. for(i=0;i<n;i++) cin>>a[i].first>>a[i].second;
  60. sort(all(a),[](auto &x, auto &y){re x.first<y.first;});
  61. for(r=0;r<n;r++)
  62. {
  63. if(dem[a[r].second]++==0) sl--;
  64. while(sl==0)
  65. {
  66. res=min(res,a[r].first-a[l].first);
  67. if(dem[a[l].second]--==1) sl++;
  68. l++;
  69. }
  70. }
  71. cout<<(res==LLONG_MAX?-1:res);
  72. }
  73. int main()
  74. {
  75. faster
  76. // bai1();
  77. // bai2();
  78. // bai3();
  79. // bai4();
  80. re 0;
  81. }
  82.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty