Submission #124630

# Submission time Handle Problem Language Result Execution time Memory
124630 2019-07-03T15:43:40 Z deinfreund CATS (NOI14_cats) C++14
4 / 25
1500 ms 132056 KB
#include <bits/stdc++.h>

using namespace std;

bool reversed[2];
vector<int> stacks[2];

void push(int s, int v){
  s--;
  if (v < 0){
    reversed[s] = !reversed[s];
  }else{
    //cout << "pushing " << v << endl;
    stacks[s].push_back(v ^ reversed[s]);
  }
}
int peek(int s){
  s--;
  if (stacks[s].empty()) return reversed[s];
  return stacks[s][stacks[s].size() - 1] ^ reversed[s];
}
int pop(int s){
  int v = peek(s);
  s--;
  if (stacks[s].empty()) return reversed[s];
  stacks[s].pop_back();
  return v;
}


int calc(int X, int L, int N){
  stacks[0].clear(); 
  stacks[1].clear(); 
  reversed[0] = 0;
  reversed[1] = 0;
  int COUNTER = X;
  while (COUNTER > 0){
    push(2, peek(1));            //Push the top element of S1 onto S2
    pop(1);                //Pop the top element of S1
    reversed[0] = !reversed[0];
    if (peek(2) > L){
      COUNTER = COUNTER - 1;
      if( COUNTER == 0) {
	return peek(2);
      }
    }
    else{
      push(2, N);
      push(2, N);
      push(2, pop(2) + pop(2));
      push(2, pop(2) + pop(2));
      push(1, peek(2));
      push(1, peek(2));
      pop(2);
      pop(2);
    }
  }
}


int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int Q;
  
  cin >> Q;
  for (int q = 0; q< Q; q++){
    int a,b,c;
    cin >>a >> b>> c;
    cout << calc(a,b,c) << endl;
  }
  
}

Compilation message

cats.cpp: In function 'int calc(int, int, int)':
cats.cpp:58:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 43 ms 504 KB Output is correct
2 Correct 32 ms 2544 KB Output is correct
3 Correct 32 ms 1468 KB Output is correct
4 Correct 24 ms 1016 KB Output is correct
5 Correct 30 ms 2544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1545 ms 2588 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1523 ms 2680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1559 ms 1520 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1564 ms 132056 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1580 ms 131904 KB Time limit exceeded
2 Halted 0 ms 0 KB -