#include <bits/stdc++.h>
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
using namespace std;
struct MyStack {
vector<int> v;
int flip = 0;
void push(int x) {
v.push_back(x);
}
int pop() {
if (!v.empty()) {
int x = v.back();
v.pop_back();
return x;
}
return flip;
}
int top() {
return v.empty() ? flip : v.back();
}
void add() {
push(pop() + pop());
}
};
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int q;
cin >> q;
while (q--) {
int x, l, n;
cin >> x >> l >> n;
MyStack s1, s2;
int counter = x;
while (counter > 0) {
s2.push(s1.pop());
for (int &i : s1.v)
i ^= 1;
s1.flip ^= 1;
if (s2.top() > l) {
counter--;
if (counter == 0)
cout << s2.top() << "\n";
}
else {
s2.push(n);
s2.push(n);
s2.add();
s2.add();
s1.push(s2.top());
s1.push(s2.top());
s2.pop();
s2.pop();
}
}
// COUNTER = X
// WHILE COUNTER > 0
// S2 PUSH T1 //Push the top element of S1 onto S2
// S1 POP //Pop the top element of S1
// FLIP LAST BINARY BIT OF ALL NUMBERS IN S1
// IF T2 > L
// COUNTER = COUNTER - 1
// IF COUNTER == 0 PRINT T2
// ELSE
// S2 PUSH N
// S2 PUSH N
// S2 ADD
// S2 ADD
// S1 PUSH T2
// S1 PUSH T2
// S2 POP
// S2 POP
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
632 KB |
Output is correct |
2 |
Correct |
15 ms |
2676 KB |
Output is correct |
3 |
Correct |
14 ms |
1528 KB |
Output is correct |
4 |
Correct |
9 ms |
1016 KB |
Output is correct |
5 |
Correct |
13 ms |
2540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
647 ms |
4240 KB |
Output is correct |
2 |
Correct |
408 ms |
4392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1531 ms |
4000 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1564 ms |
632 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1569 ms |
1296 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
949 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |