fork download
  1. #include <bits/stdc++.h>
  2. #define pii pair<int, int>
  3. #define f first
  4. #define s second
  5. #define ll long long
  6. #define oo 2000000000
  7. #define piii pair<pii, int>
  8. #define pb push_back
  9. #define mp make_pair
  10.  
  11.  
  12. using namespace std;
  13.  
  14. const int up = 1e6 + 30;
  15. int n, k, a[up];
  16. ll pw[25];
  17.  
  18. pii work(int d) {
  19. unordered_map<ll, int>cnt;
  20. ll val = 0;
  21. for(int i = 0; i < d; ++i) {
  22. val = val * k + a[i];
  23. }
  24. cnt[val]++;
  25. for(int i = d; i < n; ++i) {
  26. val = val - pw[d - 1] * a[i - d];
  27. val = val * k + a[i];
  28. cnt[val]++;
  29. }
  30. if(cnt[val] == 1) return mp(d, 0);
  31. else {
  32. for(int s = 1; s <= d; ++s) {
  33. val -= pw[d - s] * a[n - d + s - 1];
  34. for(ll i = 0; i < pw[s]; ++i) {
  35. if(!cnt.count(val * pw[s] + i)) {
  36. return mp(d, s);
  37. }
  38. }
  39. }
  40. return mp(0, 0);
  41. }
  42. }
  43. void solve() {
  44. cin >> n >> k;
  45. for(int i = 0; i < n; ++i) {
  46. cin >> a[i];
  47. --a[i];
  48. }
  49. if(k == 1) {
  50. cout << n << " 0\n";
  51. }else { /// in base k
  52. pw[0] = 1;
  53. for(int i = 1; pw[i - 1] < n; ++i) {
  54. pw[i] = pw[i - 1] * k;
  55. }
  56. for(int i = 1; i <= 20; ++i) {
  57. pii cur = work(i);
  58. if(cur.f != 0) {
  59. cout << cur.f << ' ' << cur.s << '\n';
  60. break;
  61. }
  62. }
  63. }
  64. }
  65. int main()
  66. {
  67. ios_base::sync_with_stdio(false);
  68. int t = 1;
  69. //cin >> t;
  70. while(t--) {
  71. solve();
  72. }
  73. return 0;
  74. }
  75.  
  76. /*
  77.  
  78. 10 2
  79. 1 2 1 1 2 2 1 2 1 1
  80.  
  81. */
  82.  
Success #stdin #stdout 0s 5604KB
stdin
Standard input is empty
stdout
1 0