Advertisement
huberemanuel

2659.cpp

Nov 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     int N, T, A, X, Y, begin = -1, end = -1, rest = 0, tam = 0;
  7.     vector<int> taps;
  8.     vector<int> numbers;
  9.    
  10.     cin >> N >> T >> A >> X >> Y;
  11.    
  12.     vector<int> rests(X, 0);
  13.    
  14.     for (int i = 0; i < T; i++) {
  15.         int aux;
  16.         cin >> aux;
  17.         taps.push_back(aux);
  18.     }
  19.    
  20.     if (Y == 1 && A % X == 0) begin = end = 0;
  21.    
  22.     while (begin == -1 && end == -1) {
  23.        
  24.         rest = (rest + A) % X;
  25.         numbers.push_back(A);
  26.         tam++;
  27.        
  28.         if ((rests[rest] != 0 and (tam - rests[rest]) >= Y) or (Y == 1 and A % X == 0)) {
  29.             begin = rests[rest];
  30.             end = tam - 1;
  31.             break;
  32.         }
  33.        
  34.         rests[rest] = tam;
  35.        
  36.         int bit = A & 1;
  37.         for (int i = 1; i < T; i++)
  38.             bit ^= (A >> (taps[i])) & 1;
  39.        
  40.         A >>= 1;
  41.         A |= bit << (N - 1);
  42.     }
  43.    
  44.     cout << begin << " " << end << endl;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement