답안 #124632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124632 2019-07-03T15:48:02 Z groeneprof CATS (NOI14_cats) C++14
8 / 25
1500 ms 262148 KB
#include <bits/stdc++.h>
#define int long long
#define P(x) do {if(debug) cout << x << endl;} while(false)
#define H(x) P(#x << ": " << x)
#define FR(i, a, b) for(int i = (a); i < (b); ++i)
#define F(i, n) FR(i, 0, n)
#define DR(i, a, b) for(int i = (b); i --> (a);)
#define D(i, n) DR(i, 0, n)
#define S(s) (int)(s).size()
#define ALL(x) (x).begin(), (x).end()
#define MI(x, a) (x) = min(x, a)
#define MA(x, a) (x) = max(x, a)
#define V vector
#define pb push_back
#define mp make_pair
using namespace std;
const bool debug = 1;

int top_(stack<int>& st){
	if(st.empty()) return 0;
	return	st.top();
}
void print(stack<int> st, int xr){
	while(!st.empty()){
		cout<<(st.top()^xr)<<" ";
		st.pop();
	}
	cout<<xr<<endl;
}
int f(int X, int L, int N){
	stack<int> S1, S2;
	int counter = X;
	int xr = 0;
	while(counter>0){
		//H(counter);
		//print(S1, xr);
		S2.push(top_(S1) ^ xr);
		if(!S1.empty()) S1.pop();
		xr = (xr^1);
		if(top_(S2)>L){
			counter--;
			if(counter == 0) return top_(S2);
		}
		else{
			int a = top_(S2);
			if(!S2.empty()) S2.pop();
			S2.push(a+2*N);
			S1.push(top_(S2)^xr);
			S1.push(top_(S2)^xr);
			if(!S2.empty()) S2.pop();
			if(!S2.empty()) S2.pop();
		}
	}
	return -12345;
}
signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int Q;
	cin>>Q;
	F(i, Q){
		int X, L, N;
		cin>>X>>L>>N;
		cout<<f(X, L, N)<<"\n";
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 508 KB Output is correct
2 Correct 18 ms 3576 KB Output is correct
3 Correct 16 ms 1528 KB Output is correct
4 Correct 13 ms 1272 KB Output is correct
5 Correct 15 ms 2936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 758 ms 4040 KB Output is correct
2 Correct 506 ms 4452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1542 ms 3808 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1557 ms 2540 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 867 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 869 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -